micro/fsm/fsm.go
Vasiliy Tolstov faf2454f0a cleanup
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2024-09-20 17:54:17 +03:00

30 lines
605 B
Go

package fsm
import (
"context"
"errors"
)
var (
ErrInvalidState = errors.New("does not exists")
StateEnd = "end"
)
type State interface {
Name() string
Body() interface{}
}
// StateWrapper wraps the StateFunc and returns the equivalent
type StateWrapper func(StateFunc) StateFunc
// StateFunc called on state transition and return next step and error
type StateFunc func(ctx context.Context, state State, opts ...StateOption) (State, error)
type FSM interface {
Start(context.Context, interface{}, ...Option) (interface{}, error)
Current() string
Reset()
State(string, StateFunc)
}