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.
Issue #22 - A Function to cancel a transition after StateMachine.ASYNC
Done. You can now call my-state-machine.transition.cancel() to cancel an ASYNC event transition.
Nice one. I'll try it out.