A Function to cancel a transition after StateMachine.ASYNC #22

twashing opened this Issue May 5, 2012 · 3 comments


None yet

2 participants

twashing commented May 5, 2012

Hi there,

When you return a StateMachine.ASYNC value from an event callback, the expectation is that you are later going to call my-state-machine.transition() to go to the new state. However, I can't see a way to cancel that transition if there was an error somewhere in my asynchronous callback.

Looking at the code, what I did was take my-state-machine.transition member, which is a function, and set it to false. I did this just by looking at the algorithm in the source code. But there should definitely be a function call to cancel the transition, after an StateMachine.ASYNC call. This is, unless, I've missed it in the documentation.



You are correct.

There is no formal way to cancel an ASYNC transition. As you found, you can get the effect by setting the fsm.transition member to null/false. I'll add a more formal mechanism. Probably my-state-machine.transition.cancel()

I think it should probably fire the afterevent callback, in the same way that cancelling a non-async event still fires the afterevent callback. Of course, the state itself wont change so the leavestate/enterstate callbacks dont fire.

Should be pretty straight forward. I'll add it in for the next release.



Done. You can now call my-state-machine.transition.cancel() to cancel an ASYNC event transition.

@jakesgordon jakesgordon closed this May 9, 2012
twashing commented May 9, 2012

Nice one. I'll try it out.

@mcharytoniuk mcharytoniuk pushed a commit to cruks/cruks-lib-state-machine that referenced this issue Apr 28, 2014
@jakesgordon Issue #22 - A Function to cancel a transition after StateMachine.ASYNC 0788577
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment