Created
May 15, 2019 09:59
-
-
Save boogie666/333e4ea398fbc25e50ab08f74a38f574 to your computer and use it in GitHub Desktop.
simple finite state machine runner
This file contains hidden or 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
function run(fsm, stateRunner, state){ | |
let runner = stateRunner[state.currentState]; | |
return Promise.resolve(runner(state)).then(function(transition){ | |
if(transition.transitionTo === "done"){ | |
return transition.data; | |
} | |
return run(fsm, stateRunner, { | |
...transition, | |
currentState: fsm[state.currentState][transition.transitionVia] | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment