Skip to content

Instantly share code, notes, and snippets.

@majorz
Created October 20, 2010 22:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save majorz/637452 to your computer and use it in GitHub Desktop.
Save majorz/637452 to your computer and use it in GitHub Desktop.
Sample state machine control flow
def initial():
do_some_initialization()
def first_branch(data):
pass
def default_branch(data):
pass
def should_execute_first(data):
return data > 10
machine = StateMachine(initial)
machine.transition(initial, first_branch, guard=should_execute_first)
machine.transition(initial, default_branch)
machine.initiate() # this will execute the 'initial' function
machine.process_event(40) # since 40 > 10, it will execute 'first_branch', otherwise it will execute 'default_branch'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment