fsm-as-promised: callback error handling
var StateMachine = require('fsm-as-promised');
var assert = require('assert');
var fsm = StateMachine({
initial: 'stopped',
events: [{
name: 'start',
from: 'stopped',
to: 'started'
}],
callbacks: {
onleavestopped: function(opts) {
opts.foo = opts.args[0];
return opts;
},
onleave: function(opts) {
assert(opts.foo === 0);
opts.foo++;
return opts;
},
onstart: function(opts) {
assert(opts.foo === 1);
opts.foo++;
return opts;
},
onenterstarted: function(opts) {
assert(opts.foo === 2);
opts.foo++;
return opts;
},
onenter: function(opts) {
assert(opts.foo === 3);
opts.foo++;
return opts;
},
onenteredstarted: function(opts) {
assert(opts.foo === 5);
opts.foo++;
return opts;
},
onentered: function(opts) {
assert(opts.foo === 6);
opts.foo++;
return opts;
}
}
});
fsm.start(0)
.catch(function(err) {
// what is value of foo?
console.log(err);
console.log(fsm.current);
});
no comments