fsm

package
v0.0.0-...-ee95d54 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2023 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StateGlobalIdle = State("__idle")
	StateGlobalDone = State("__done")
)

Temporary global finish state for deprecating operations

Variables

This section is empty.

Functions

func Visualize

func Visualize(fsm *FSM) string

Types

type Callback

type Callback func(event Event, args ...interface{}) (Event, interface{}, error)

type Callbacks

type Callbacks map[Event]Callback

type Event

type Event string

func (Event) IsEmpty

func (e Event) IsEmpty() bool

func (*Event) String

func (e *Event) String() string

type EventDesc

type EventDesc struct {
	Name Event

	SrcState []State

	// Dst state changes after callback
	DstState State

	// Internal events, cannot be emitted from external call
	IsInternal bool

	// Event must run without manual call
	IsAuto bool

	AutoRunMode EventRunMode
}

type EventRunMode

type EventRunMode uint8
const (
	EventRunDefault EventRunMode = iota
	EventRunBefore
	EventRunAfter
)

type FSM

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

func MustNewFSM

func MustNewFSM(machineName string, initialState State, events []EventDesc, callbacks Callbacks) *FSM

func (*FSM) Do

func (f *FSM) Do(event Event, args ...interface{}) (resp *Response, err error)

func (*FSM) EntryEvent

func (f *FSM) EntryEvent() (event Event)

func (*FSM) EventsList

func (f *FSM) EventsList() (events []Event)

func (*FSM) GlobalInitialEvent

func (f *FSM) GlobalInitialEvent() (event Event)

Check entry event for available emitting as global entry event

func (*FSM) InitialState

func (f *FSM) InitialState() State

func (*FSM) IsFinState

func (f *FSM) IsFinState(state State) bool

func (*FSM) MustCopyWithState

func (f *FSM) MustCopyWithState(state State) *FSM

WithState returns FSM copy with custom setup state

func (*FSM) Name

func (f *FSM) Name() string

func (*FSM) SetState

func (f *FSM) SetState(event Event) error

SetState allows the user to move to the given state from currentState state. The call does not trigger any callbacks, if defined.

func (*FSM) State

func (f *FSM) State() State

State returns the currentState state of the FSM.

func (*FSM) StatesList

func (f *FSM) StatesList() (states []State)

type Response

type Response struct {
	// Returns machine execution result state
	State State
	// Must be cast, according to mapper event_name->response_type
	Data interface{}
}

Response returns result for processing with clientMocks events

type State

type State string

func (*State) String

func (s *State) String() string

Jump to

Keyboard shortcuts

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