fsm icon indicating copy to clipboard operation
fsm copied to clipboard

Multiple callback coverage bugs for the same event

Open chyroc opened this issue 6 years ago • 1 comments

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

chyroc avatar Apr 14 '19 10:04 chyroc

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

chyroc avatar Apr 14 '19 10:04 chyroc