fsm

package
v3.9.8 Latest Latest
Warning

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

Go to latest
Published: May 2, 2022 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

This section is empty.

Types

type FSM

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

FSM is a finite state machine

func New

func New(opts ...Option) *FSM

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

func (*FSM) Current

func (f *FSM) Current() string

Current returns the current state

func (*FSM) Reset

func (f *FSM) Reset()

Current returns the current state

func (*FSM) Start

func (f *FSM) Start(ctx context.Context, args interface{}, opts ...Option) (interface{}, error)

Start runs state machine with provided data

func (*FSM) State

func (f *FSM) State(state string, fn StateFunc)

State adds state to fsm

type HookAfterFunc

type HookAfterFunc func(ctx context.Context, state string, args interface{})

HookAfterFunc func signature

type HookBeforeFunc

type HookBeforeFunc func(ctx context.Context, state string, args interface{})

HookBeforeFunc func signature

type Option

type Option func(*Options)

Option func signature

func HookAfter

func HookAfter(fns ...HookAfterFunc) Option

HookAfter provides hook func slice

func HookBefore

func HookBefore(fns ...HookBeforeFunc) Option

HookBefore provides hook func slice

func InitialState

func InitialState(initial string) Option

InitialState sets init state for state machine

type Options

type Options struct {
	// DryRun mode
	DryRun bool
	// Initial state
	Initial string
	// HooksBefore func slice runs in order before state
	HooksBefore []HookBeforeFunc
	// HooksAfter func slice runs in order after state
	HooksAfter []HookAfterFunc
}

Options struct holding fsm options

type StateFunc

type StateFunc func(ctx context.Context, args interface{}, opts ...StateOption) (string, interface{}, 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

Jump to

Keyboard shortcuts

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