Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing Event.Dst in before-event callback do not changing dst of transition #103

Open
naumov-andrey opened this issue Nov 21, 2023 · 1 comment

Comments

@naumov-andrey
Copy link

Hi,
I have no effect on dst when changing it in pointer to Event in before-event callback

e.g.

package main

import (
	"context"
	"fmt"

	"github.com/looplab/fsm"
)

func main() {
	fsm := fsm.NewFSM(
		"start",
		fsm.Events{
			{Name: "created", Src: []string{"start"}, Dst: "checked"},
		},
		fsm.Callbacks{
			"before_created": func(ctx context.Context, e *fsm.Event) {
				// some checks
				e.Dst = "start"
			},
		},
	)

	if err := fsm.Event(context.Background(), "created"); err != nil {
		panic(fmt.Sprintf("Error encountered when triggering the run event: %v", err))
	}

	fmt.Println(fsm.Current())
}

Output:

-> % go run -mod=vendor .
checked

Is it design way?
How can I implement dynamic event handling?

@naumov-andrey
Copy link
Author

naumov-andrey commented Nov 21, 2023

e.Cancel() fits for this case when I just want to not transit to dst state
However the topic is still actual

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant