fsm

package
v0.0.0-...-7686319 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 30, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

README

fsm

a finite-state machine pattern in Go

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTransitionNotFound = errors.New("fsm: transition was not found")
	ErrInvalidState       = errors.New("fsm: inappropriate in current state")
)

Functions

This section is empty.

Types

type Event

type Event struct {
	StateMachine *StateMachine
	Transitions  string
	From         string
	To           string
	Args         []interface{}
}

type Handler

type Handler func(ctx context.Context, e *Event) error

type StateMachine

type StateMachine struct {
	// contains filtered or unexported fields
}

func New

func New(initialState string) *StateMachine

func (*StateMachine) Can

func (sm *StateMachine) Can(transition string) bool

func (*StateMachine) Cannot

func (sm *StateMachine) Cannot(transition string) bool

func (*StateMachine) Is

func (sm *StateMachine) Is(sate string) bool

func (*StateMachine) SetState

func (sm *StateMachine) SetState(state string)

func (*StateMachine) State

func (sm *StateMachine) State() string

func (*StateMachine) Transition

func (sm *StateMachine) Transition(name string) *Transition

func (*StateMachine) Trigger

func (sm *StateMachine) Trigger(ctx context.Context, transition string, args ...interface{}) error

type Transition

type Transition struct {
	// contains filtered or unexported fields
}

func (*Transition) After

func (t *Transition) After(h Handler) *Transition

func (*Transition) AfterTransition

func (t *Transition) AfterTransition(h Handler) *Transition

func (*Transition) Before

func (t *Transition) Before(h Handler) *Transition

func (*Transition) BeforeTransition

func (t *Transition) BeforeTransition(h Handler) *Transition

func (*Transition) EnterState

func (t *Transition) EnterState(state string, h Handler) *Transition

func (*Transition) From

func (t *Transition) From(states ...string) *Transition

func (*Transition) LeaveState

func (t *Transition) LeaveState(state string, h Handler) *Transition

func (*Transition) StateMachine

func (t *Transition) StateMachine() *StateMachine

func (*Transition) To

func (t *Transition) To(state string) *Transition

func (*Transition) Transition

func (t *Transition) Transition(name string) *Transition

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL