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, thanks for this great state machine library and I meent a problem when using it.
I have a trigger named "shutdown machine", and it can be fired at any state, which will result in back to the very original state. How to implement this? Adding the trigger to every state?
The text was updated successfully, but these errors were encountered:
I know this is a long time ago, but you can also achieve this by using substates. See the test below as an example:
funcTestOnOffSuperstates(t*testing.T) {
fsm:=stateless.NewStateMachine("on1")
// configure the on superstatefsm.Configure("on").
InitialTransition("on1").
Permit("shutdown", "off")
// configure the off superstatefsm.Configure("off").
Permit("turn-on", "on")
// configure on1, substate of onfsm.Configure("on1").
SubstateOf("on")
// configure on2, substate of onfsm.Configure("on2").
SubstateOf("on")
// we are on, firing shutdown should get us in the off statefsm.Fire("shutdown")
iffsm.MustState() !="off" {
t.Error("Expected state to be off")
}
// we are off, firing turn-on should get us in the on -> on1 statefsm.Fire("turn-on")
iffsm.MustState() !="on1" {
t.Error("Expected state to be on1")
}
}
You still need to tell each substate that it is a sustate of on, but I think is more elegant than defining the trigger on every state.
Hi, thanks for this great state machine library and I meent a problem when using it.
I have a trigger named "shutdown machine", and it can be fired at any state, which will result in back to the very original state. How to implement this? Adding the trigger to every state?
The text was updated successfully, but these errors were encountered: