You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Returning a Promise from a lifecycle event will cause the lifecycle for that transition to pause. It can be continued by resolving the promise, or cancelled by rejecting the promise.
Rejecting a promise returned in a lifecycle event should cancel the transition, as it happens when returning false on some lifecycle events like onTransition and onBeforeTransition.
But rejecting the returned promise doesn't have this effect, the transition completes as if the promise was resolved correctly, which can be demonstrated with this code
stateMachine.state: open
error: failed close
stateMachine.state: closed
error: transition is invalid in current state
stateMachine.state: closed
The code above should end up transitioning the state from open to requiresInfo, but instead it perform the close transition. There's no actual waiting on the promise, as the catch is only called after all lifecycle events trigger. Changing
stateMachine.state: open # right before calling stateMachine.close()
onBeforeTransition
onBeforeClose
onLeaveState
onLeaveOpen
onTransition
doTransit
doTransit
onEnterState
onEnterClosed
onClosed
onAfterTransition
onAfterClose
onClose
called catch # here the catch is handled, no other lifecycle event should trigger while the promise is still pending
error: failed close
stateMachine.state: closed
When writing this issue I actually noticed that the problem is that there's no waiting on the resolve or reject of a promise, the other lifecycleEvents are triggered no matter what happens with the promise.
The text was updated successfully, but these errors were encountered:
According to the Asynchronous Transitions doc
Rejecting a promise returned in a lifecycle event should cancel the transition, as it happens when returning
false
on some lifecycle events likeonTransition
andonBeforeTransition
.But rejecting the returned promise doesn't have this effect, the transition completes as if the promise was resolved correctly, which can be demonstrated with this code
Output:
stateMachine.state: open error: failed close stateMachine.state: closed error: transition is invalid in current state stateMachine.state: closed
The code above should end up transitioning the state from
open
torequiresInfo
, but instead it perform theclose
transition. There's no actual waiting on the promise, as thecatch
is only called after all lifecycle events trigger. Changingjavascript-state-machine/src/jsm.js
Line 157 in 0d60357
And adding a
console.log(event)
right beforejavascript-state-machine/src/jsm.js
Line 148 in 0d60357
When writing this issue I actually noticed that the problem is that there's no waiting on the resolve or reject of a promise, the other lifecycleEvents are triggered no matter what happens with the promise.
The text was updated successfully, but these errors were encountered: