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
Hi, this feature has been recently added and I wanted to discuss it:
The current code base implements the following order for transitioning from State1 to State2:
Transition action is executed.
on_exit hook of State1 is called.
on_entry hook of State2 is called.
The state machine transitions to State2.
I think this order should be changed to the following for better consistency and integrity:
on_exit hook of State1 is called.
Transition action is executed.
The state machine transitions to State2.
on_entry hook of State2 is called.
Here are my points to support this:
The on_exit is the hook of Current State. It is responsible for finalisation tasks before leaving the current state. It must operate while the state machine is still in the the current state
Action is what the state change starts from. It can potentially modify the extended state, towards transitioning. After action is complete the state machine is half way in the transition. It's already not in Current State (as its changed the extended state) and isn't yet in New State (it has not yet assigned the new state to self.state ). The update of the state machine's internal state, completes the transition.
The on_entry is the hook of New State is responsible for initialisation tasks for the new state. These tasks must be performed after the state machine has transitioned to the new state.
Integrity consideration: If the state machine were to execute the transition action before the on_exit of the current state, it could lead to inconsistencies. For example, an action may return an error. That means that the state machine is not going to leave the current state, hence invoking on_exit in this situation is inconsistent with the definition of on_exit. Another example, resources that should be cleaned up in the on_exit might still be in use during the transition action, leading to potential errors or undefined behaviour.
The text was updated successfully, but these errors were encountered:
Hi, this feature has been recently added and I wanted to discuss it:
The current code base implements the following order for transitioning from State1 to State2:
I think this order should be changed to the following for better consistency and integrity:
Here are my points to support this:
The on_exit is the hook of Current State. It is responsible for finalisation tasks before leaving the current state. It must operate while the state machine is still in the the current state
Action is what the state change starts from. It can potentially modify the extended state, towards transitioning. After action is complete the state machine is half way in the transition. It's already not in Current State (as its changed the extended state) and isn't yet in New State (it has not yet assigned the new state to self.state ). The update of the state machine's internal state, completes the transition.
The on_entry is the hook of New State is responsible for initialisation tasks for the new state. These tasks must be performed after the state machine has transitioned to the new state.
Integrity consideration: If the state machine were to execute the transition action before the on_exit of the current state, it could lead to inconsistencies. For example, an action may return an error. That means that the state machine is not going to leave the current state, hence invoking on_exit in this situation is inconsistent with the definition of on_exit. Another example, resources that should be cleaned up in the on_exit might still be in use during the transition action, leading to potential errors or undefined behaviour.
The text was updated successfully, but these errors were encountered: