Branching flow

Green
Yellow
Red

This example demonstrates a more complicated, state-dependent flow (copying Jake Gordon's JavaScript State Machine demo):

There are a variety of interacting states and actions, as well as an asynchronous event handler on leaving the red state.

Note that the configuration for this state machine was written using shorthand notation:


        

Had it been written in JavaScript, it would have looked like this:

{action: 'warn',   from: 'green',  to: 'yellow'},
{action: 'panic',  from: 'green',  to: 'red'},
{action: 'clear',  from: 'yellow', to: 'green'},
{action: 'panic',  from: 'yellow', to: 'red'},
{action: 'clear',  from: 'red',    to: 'green'},
{action: 'calm',   from: 'red',    to: 'yellow'},
{action: 'finish', from: 'red',    to: 'final'}