Versions in this module Expand all Collapse all v1 v1.0.0 Aug 8, 2026 Changes in this version + var ErrInvalidTransition = errors.New("invalid transition") + var ErrReentrant = errors.New("reentrant call from hook") + var ErrUnknownState = errors.New("unknown state") + type Change struct + From S + To S + type EventGraph struct + func (g EventGraph[S, E]) Mermaid() string + func (g EventGraph[S, E]) String() string + type EventGraphBuilder struct + func NewEventGraph[S, E ~string]() *EventGraphBuilder[S, E] + func (b *EventGraphBuilder[S, E]) Build() (EventGraph[S, E], error) + func (b *EventGraphBuilder[S, E]) MustBuild() EventGraph[S, E] + func (b *EventGraphBuilder[S, E]) On(from S, event E, to S) *EventGraphBuilder[S, E] + type EventMachine struct + func MustEventMachine[S, E ~string](graph EventGraph[S, E], initial S) *EventMachine[S, E] + func NewEventMachine[S, E ~string](graph EventGraph[S, E], initial S) (*EventMachine[S, E], error) + func (m *EventMachine[S, E]) CanFire(ctx context.Context, event E) error + func (m *EventMachine[S, E]) Current() S + func (m *EventMachine[S, E]) Fire(ctx context.Context, event E) error + func (m *EventMachine[S, E]) ForceState(state S) error + func (m *EventMachine[S, E]) Guard(from S, event E, hook Hook[S, E]) *EventMachine[S, E] + func (m *EventMachine[S, E]) Is(state S) bool + func (m *EventMachine[S, E]) OnEnter(state S, hook Hook[S, E]) *EventMachine[S, E] + func (m *EventMachine[S, E]) OnExit(state S, hook Hook[S, E]) *EventMachine[S, E] + func (m *EventMachine[S, E]) OnExitBlocking(state S, hook Hook[S, E]) *EventMachine[S, E] + func (m *EventMachine[S, E]) String() string + type Graph struct + func (g Graph[S]) Mermaid() string + func (g Graph[S]) String() string + type GraphBuilder struct + func NewGraph[S ~string]() *GraphBuilder[S] + func (b *GraphBuilder[S]) Build() (Graph[S], error) + func (b *GraphBuilder[S]) MustBuild() Graph[S] + func (b *GraphBuilder[S]) To(from S, to ...S) *GraphBuilder[S] + type Hook func(context.Context, Transition[S, E]) error + type Machine struct + func MustNew[S ~string](graph Graph[S], initial S) *Machine[S] + func New[S ~string](graph Graph[S], initial S) (*Machine[S], error) + func (m *Machine[S]) CanTransitionTo(ctx context.Context, to S) error + func (m *Machine[S]) Current() S + func (m *Machine[S]) ForceState(state S) error + func (m *Machine[S]) Guard(from, to S, hook StateHook[S]) *Machine[S] + func (m *Machine[S]) Is(state S) bool + func (m *Machine[S]) OnEnter(state S, hook StateHook[S]) *Machine[S] + func (m *Machine[S]) OnExit(state S, hook StateHook[S]) *Machine[S] + func (m *Machine[S]) OnExitBlocking(state S, hook StateHook[S]) *Machine[S] + func (m *Machine[S]) String() string + func (m *Machine[S]) TransitionTo(ctx context.Context, to S) error + type Phase uint8 + const PhaseEnter + const PhaseExit + const PhaseGuard + const PhaseResolve + func (p Phase) String() string + type StateHook func(context.Context, Change[S]) error + type Transition struct + Event E + From S + To S + type TransitionError struct + Committed bool + Err error + Event E + From S + Phase Phase + To S + func (e *TransitionError[S, E]) Error() string + func (e *TransitionError[S, E]) Moved() bool + func (e *TransitionError[S, E]) Unwrap() error