fsm

package
v0.0.0-...-8bba7c7 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2020 License: MIT Imports: 1 Imported by: 0

README

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FSM

type FSM struct {
	State          string
	StateDirectory map[string]State
	ErrorHandler   func(*FSM, error)
}

FSM represents a Finite State Machine, which can have one State active at a time.

func NewFSM

func NewFSM() *FSM

NewFSM creates a new FSM and returns it.

func (*FSM) Change

func (f *FSM) Change(stateName string)

Change allows you to change the current, "main" State assigned to the FSM. If you run Change(), it will call Exit() on the previous State and Enter() on the next State.

func (*FSM) HasState

func (f *FSM) HasState(name string) bool

HasState returns if the FSM has a State associated with the name in its directory.

func (*FSM) Register

func (f *FSM) Register(name string, state State)

Register registers a State with its name.

func (*FSM) Unregister

func (f *FSM) Unregister(name string)

Unregister removes a State from the FSM using its name.

func (*FSM) Update

func (f *FSM) Update()

Update runs the Update() on the active State.

type State

type State struct {
	Enter  func() error
	Update func() error
	Exit   func() error
}

State is a basic struct that implements the State interface.

Jump to

Keyboard shortcuts

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