fsm

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2022 License: MIT Imports: 4 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event uint32

Event represents FSM event

const (
	// Initialize func
	Initialize Event = iota // Init func
	// Start func
	Start // Serve func
	// Stop func
	Stop // Stop func
)

func (Event) String

func (ev Event) String() string

type FSM

type FSM interface {
	// CurrentState returns the current state of the FSM
	CurrentState() State
	// InitialState sets the initial FSM state
	InitialState(st State)
	// Transition used to move from one state to another
	Transition(event Event, args ...interface{}) (interface{}, error)
}

FSM represents endure finite state machine

type FSMImpl

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

FSMImpl is endure FSM interface implementation

func NewFSM

func NewFSM(initialState State, callbacks map[Event]reflect.Method) *FSMImpl

NewFSM returns new FSM implementation based on initial state and callbacks to move from one state to another

func (*FSMImpl) CurrentState

func (f *FSMImpl) CurrentState() State

CurrentState (see interface)

func (*FSMImpl) InitialState

func (f *FSMImpl) InitialState(st State)

InitialState (see interface)

func (*FSMImpl) Transition

func (f *FSMImpl) Transition(event Event, args ...interface{}) (interface{}, error)

Transition moves endure from one state to another Rules: Transition table: Event -> Init. Error on other events (Start, Stop) 1. Initializing -> Initialized Event -> Start. Error on other events (Initialize, Stop) 2. Starting -> Started Event -> Stop. Error on other events (Start, Initialize) 3. Stopping -> Stopped

type State

type State uint32

State is the FSM current state

const (
	// Uninitialized state
	Uninitialized State = iota
	// Initializing state
	Initializing
	// Initialized state
	Initialized
	// Starting state
	Starting
	// Started state
	Started
	// Stopping state
	Stopping
	// Stopped state
	Stopped
	// Error state
	Error
)

func (State) String

func (st State) String() string

Jump to

Keyboard shortcuts

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