Skip to content

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

Description

@naumov-andrey

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions