fsm

package
v4.0.8 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2023 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

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

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

func NewOptions(opts ...Option) Options

NewOptions returns new Options struct filled by passed Option

type State

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

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