Open ettersi opened 2 months ago
Terminate should not call action directly. State transitions should occur only on the main thread of the fsm. A simple fix may be to ignore state changes once the next state is marked as FINAL.
State transitions should occur only on the main thread of the fsm.
AFAICT, only agents have threads, not behaviours? So as long you call the fsm.action()
on the agent's thread, you should be fine? Having said that, I agree that ignoring state changes out of FINAL should work also.
The behaviour of
fsm.terminate()
is somewhat unfortunate: it only sets the next state toFINAL
but doesn't actually enter that state until the FSM runs again. This means that if any piece of code callsfsm.setNextState()
between thefsm.terminate()
and the FSM actually terminating (e.g. by reacting to an incoming message, or in anonExit()
hook), then thefsm.terminate()
is effectively ignored.I believe an easy way to fix this is to add an
fsm.action()
immediately after thefsm.terminate()
. This way, we both suggest the state transition to the FSM and immediately execute, and therefore this makes sure that no other code can override the state transition. We may want to consider adding this fix tofsm.terminate()
.