fsm

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2021 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action interface {
	Execute(ctx context.Context) EventType
}

Action represents the action to be executed in a given state.

type EventType

type EventType string

EventType represents an extensible event type in the state machine.

type Events

type Events map[EventType]StateType

Events represents a mapping of events and states.

type Machine

type Machine struct {

	// OnTransition called when transitioning from current StateType to the nextStateType
	OnTransition func(curr, next StateType)
	// contains filtered or unexported fields
}

Machine represents the state machine.

func New

func New(curr StateType, states States) *Machine

New create new finite-state Machine with initial StateType and States mapping.

func (*Machine) GetStates

func (s *Machine) GetStates() (prev, curr StateType)

GetStates tuple of previous and current state

func (*Machine) SendEvent

func (s *Machine) SendEvent(ctx context.Context, event EventType) (err error)

SendEvent sends an event to the state machine.

type State

type State struct {
	Action
	Events
}

State binds a state with an action and a set of events it can handle.

type StateType

type StateType string

StateType represents an extensible state type in the state machine.

type States

type States map[StateType]State

States represents a mapping of states and their implementations.

Jump to

Keyboard shortcuts

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