fsm

package
v3.10.62 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidState = errors.New("does not exists")
	StateEnd        = "end"
)

Functions

func NewFSM added in v3.10.5

func NewFSM(opts ...Option) *fsm

NewFSM creates a new finite state machine having the specified initial state with specified options

Types

type FSM

type FSM interface {
	Start(context.Context, interface{}, ...Option) (interface{}, error)
	Current() string
	Reset()
	State(string, StateFunc)
}

type Option

type Option func(*Options)

Option func signature

func InitialState

func InitialState(initial string) Option

InitialState sets init state for state machine

func WrapState added in v3.10.5

func WrapState(w StateWrapper) Option

WrapState adds a state Wrapper to a list of options passed into the fsm

type Options

type Options struct {
	// Initial state
	Initial string
	// Wrappers runs before state
	Wrappers []StateWrapper
	// DryRun mode
	DryRun bool
}

Options struct holding fsm options

func NewOptions added in v3.10.5

func NewOptions(opts ...Option) Options

NewOptions returns new Options struct filled by passed Option

type State added in v3.10.5

type State interface {
	Name() string
	Body() interface{}
}

type StateFunc

type StateFunc func(ctx context.Context, state State, opts ...StateOption) (State, error)

StateFunc called on state transition and return next step and error

type StateOption

type StateOption func(*StateOptions)

StateOption func signature

func StateDryRun

func StateDryRun(b bool) StateOption

StateDryRun says that state executes in dry run mode

type StateOptions

type StateOptions struct {
	DryRun bool
}

StateOptions holds state options

type StateWrapper added in v3.10.5

type StateWrapper func(StateFunc) StateFunc

StateWrapper wraps the StateFunc and returns the equivalent

Jump to

Keyboard shortcuts

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