Skip to content

Instantly share code, notes, and snippets.

@boogie666
Created May 15, 2019 09:59
Show Gist options
  • Save boogie666/333e4ea398fbc25e50ab08f74a38f574 to your computer and use it in GitHub Desktop.
Save boogie666/333e4ea398fbc25e50ab08f74a38f574 to your computer and use it in GitHub Desktop.
simple finite state machine runner
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