statemachine icon indicating copy to clipboard operation
statemachine copied to clipboard

Stop/abort passive state machine

Open dmumladze opened this issue 6 years ago • 3 comments

Question: Is there a way to abort the state machine to prevent any further transitions? I used the Stop() method, but it doesn't stop it. I understand it may not be recommended to do so, but there's no need to keep transitioning if there's an transient exceptions and whatnot... Could you please suggest a recommended way to deal with such cases?

dmumladze avatar Oct 30 '19 23:10 dmumladze

Can you proved more information why stop didn't work? Was it an active or passive, an async or synchronous state machine? The behaviour of Stops is different for the 4 kinds of machines.

For exceptions, you can introduce a global transition (pack all states into a superstate that has this transition) for exceptions and fire an event representing this scenario with FirePriority so that it gets to the head of the queue of events to process.

ursenzler avatar Oct 31 '19 11:10 ursenzler

It's AsyncPassiveStateMachine. As it transitions though states, I see TransitionExceptionThrown event triggering, but it keep going without stopping. I tried to call Stop in TransitionExceptionThrown handler, but state machine does not stop.

dmumladze avatar Nov 01 '19 16:11 dmumladze

Yes, the passive state machines continue executing the current "stack" of events and will only stop once they are all executed. The state machine will pass exceptions to your code (via the event handler) and continue running. For me, that is the best the state machine can do. If you want to state machine to throw an exception, don0t register a listener for TransitionExceptionThrown. The state machine checks whether there is a listener.

ursenzler avatar Nov 30 '19 12:11 ursenzler