fsm

package
v0.6.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterStateMachine

func RegisterStateMachine(sm StateMachine)

Types

type Action

type Action string

Action define the action type.

type Factory

type Factory interface {
	Register(StateMachine)
	Get(string) (StateMachine, bool)
}

Factory define the factory interface.

func NewStateFactory

func NewStateFactory() Factory

type SimpleState

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

func NewSimpleState

func NewSimpleState(label StateLabel) *SimpleState

func (*SimpleState) Context

func (s *SimpleState) Context() StateContext

func (*SimpleState) Label

func (s *SimpleState) Label() StateLabel

func (*SimpleState) SetContext

func (s *SimpleState) SetContext(context StateContext)

type State

type State interface {
	SetContext(StateContext) // set the state context
	Context() StateContext
	Label() StateLabel // get the state label
}

State define the state interface.

type StateBuilder

type StateBuilder func() State

StateBuilder define the state builder interface.

type StateContext

type StateContext interface {
	CurrentState() State                      // get the current state
	TransitionTo(next State, by Action) error // transition to the next state
}

StateContext define the state context interface.

type StateLabel

type StateLabel string

StateLabel define the state type.

type StateMachine

type StateMachine interface {
	Name() string                                              // get the state machine name
	AddTransition(from, to StateLabel, action Action) error    // add a transition
	HasTransition(from StateLabel, action Action) bool         // check if has transition from one state to another
	TransitionToNext(StateContext, Action) error               // transition to the next state
	Check() error                                              // Check the completeness of States and Transitions.
	RegisterStateBuilder(label StateLabel, state StateBuilder) // register a state
}

StateMachine define the state machine interface.

func GetStateMachine

func GetStateMachine(name string) (StateMachine, bool)

func MustGetStateMachine

func MustGetStateMachine(name string) StateMachine

func NewStateMachine

func NewStateMachine(name string) StateMachine

type TransitionError

type TransitionError struct {
	Action  Action
	Current StateLabel
}

func NewTransitionError

func NewTransitionError(current StateLabel, action Action) *TransitionError

func (*TransitionError) Error

func (te *TransitionError) Error() string

Jump to

Keyboard shortcuts

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