func main() {
f := fsm.NewFSM(
"start",
fsm.Events{
{Name: "run_async", Src: []string{"start"}, Dst: "end"},
{Name: "run", Src: []string{"start"}, Dst: "end"},
},
fsm.Callbacks{
"leave_start": func(_ context.Context, e *fsm.Event) {
if e.Event == "run_async" {
e.Async()
}
},
},
)
err := f.Event(context.Background(), "run_async")
asyncError, ok := err.(fsm.AsyncError)
if !ok {
panic("!ok")
}
//do something failed
asyncError.CancelTransition()
if err := f.Transition(); err != nil {
panic(fmt.Sprintf("Transition err:%v", err))
}
if err := f.Event(context.Background(), "run"); err != nil {
panic(fmt.Sprintf("run event err:%v", err))
}
}
I use the
CancelTransitionmethod and want to cancel a transition while do some thing failed in the callback , but it complainevent run1 inappropriate because previous transition did not completeafter I cancel the transition and input a new event.it complain
panic: run event err:event run inappropriate because previous transition did not complete