Created
October 20, 2010 22:21
-
-
Save majorz/637452 to your computer and use it in GitHub Desktop.
Sample state machine control flow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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