qmuntal / stateless

Go library for creating finite state machines
BSD 2-Clause "Simplified" License
942 stars 49 forks source link

OnExit got no arguments, but OnEntry can get arguments #17

Closed okhowang closed 3 years ago

okhowang commented 3 years ago

reproducible example

package main

import (
    "context"
    "fmt"
    "github.com/qmuntal/stateless"
)

func main() {
    sm := stateless.NewStateMachine("a")
    sm.Configure("a").OnExit(func(ctx context.Context, i ...interface{}) error {
        fmt.Printf("exit A:%+v\n", i)
        return nil
    }).Permit("toB", "b")
    sm.Configure("b").OnEntry(func(ctx context.Context, i ...interface{}) error {
        fmt.Printf("enter B:%+v\n", i)
        return nil
    })
    sm.Fire("toB", 1)
}

expected output

exit A:[1]
enter B:[1]

actual output

exit A:[]
enter B:[1]