fsm
fsm copied to clipboard
Multiple callback coverage bugs for the same event
bug code:
package main
import (
"fmt"
"github.com/looplab/fsm"
)
func main() {
fsm := fsm.NewFSM(
"idle",
fsm.Events{
{Name: "scan", Src: []string{"idle"}, Dst: "scanning"},
},
fsm.Callbacks{
"after_scan": func(e *fsm.Event) {
fmt.Println("after_scan: " + e.FSM.Current())
},
"scan": func(e *fsm.Event) {
fmt.Println("scan: " + e.FSM.Current())
},
},
)
fmt.Println(fsm.Current())
if err := fsm.Event("scan"); err != nil {
fmt.Println(err)
}
}
two callback all store in map as key: cKey{"scan", callbackAfterEvent}
so bug is coming
maybe i can make a pr to fix ?
Remove the event's callback, or have them become two callbacks, and let the event's callback be executed after after_event