(node:31608) Warning: a promise was created in a handler but was not returned from it
Closed this issue · 8 comments
Calling either stateMachine.jump('first', 'second');
or stateMachine.jump('first', 'second').then(...);
seems to result in an unhandled Promise somewhere inside the state machine:
(node:31608) Warning: a promise was created in a handler but was not returned from it
Haven't digged into the code yet, but it should be possible to get rid of this, shouldn't it?
Passing multiple arguments to event calls is well supported feature of the library. There are test regarding it.
Can you post a scale down version of a state machine that can replicate this behaviour, including details of your environment (node version, promise lib used, etc).
I'm using Node 6 with Bluebird Promises. It's basically just one of the examples you listed in the README, which I tried integrating into my code. The issue here is not actually passing two arguments to the event, but rather that the state machine seems to run a Promise but not handle its return.
Still, can you post here the state machine code so that we have a common discussion ground.
Thanks!
Looking at what Bluebird says about this error seems that some of the examples are causing this as they do not explicitly return something.
The actual promises/callbacks are not part of the library and you have to be carefully when you create them so that you follow all the constraints of the promise library that you use.
{ name: 'stateone', from: 'here', to: 'there' },
{ name: 'statetwo', from: 'there', to: 'nowhere' }
That's my events array. initial
is set to here
. I then perform the following:
stateMachine.stateone('first', 'second').then(foo => {
return console.log(foo);
});
What I see in the command line then:
(node:35822) Warning: a promise was created in a handler but was not returned from it
{ name: 'stateone',
from: 'here',
to: 'there',
args: [ 'first', 'second' ] }
I tried to remove stateMachine.Promise = Promise
(from Bluebird), in order for it to use the native Promise
implementation.
I don't have access to a computer right now but I think that this is caused by the arrow function. Can you try converting to classic function.
The library is based on Promises but other ES6 features haven't been tested
I have tried this and works without any errors with all promise libs listed in documentation:
var fsm = StateMachine({
initial: 'here',
events: [
{ name: 'one', from: 'here', to: 'there' },
{ name: 'two', from: 'there', to: 'nowhere' }
],
callbacks: {
onone: opts => {
expect(opts).to.be.deep.equal({ name: 'one', from: 'here', to: 'there', args: [] });
}
}
}, {
key: 'value'
});
fsm.one().then(opts => {
expect(opts).to.be.deep.equal({ name: 'one', from: 'here', to: 'there', args: [] });
done();
});
Using arrow function in callback behave different as this
is the object containing the state machine configuration instead of the actual state machine object as for normal function callbacks.
please reopen if you have more details