Im am not completely sure, but there seems to be a simple solution with the already existing Espruino StateMachine module:
Why no do the actual asynchronous work in the "enter" function of each state, and then trigger a state transition in the last "then" block of the chained Promises as follows:
In the "signal" function of the respective state there could be code that decides - based on the parameter on the "signal" call (here: 'good' or 'bad') - to which new state to transition:
function signalOne(result, e) {
console.log("signal one with parameters", result, e);
if ('good' === result) {
return {state:'Two', wait:(e)?e:0};
} else if ('bad' === result) {
return {state:'Error', wait:(e)?e:0};
}
};
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Im am not completely sure, but there seems to be a simple solution with the already existing Espruino StateMachine module:
Why no do the actual asynchronous work in the "enter" function of each state, and then trigger a state transition in the last "then" block of the chained Promises as follows:
In the "signal" function of the respective state there could be code that decides - based on the parameter on the "signal" call (here: 'good' or 'bad') - to which new state to transition:
I think this will fit my needs.