fsm

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2019 License: BSD-2-Clause Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

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

func NewEvent

func NewEvent(name string, data interface{}) *Event

func (*Event) Data

func (this *Event) Data() interface{}

func (*Event) From

func (this *Event) From() *State

func (*Event) Name

func (this *Event) Name() string

type State

type State struct {

	// OnEnter is called when entering a state
	// when there is a transition A -> B where A != B
	OnEnter func(*Event)
	// OnExit is called when exiting a state
	// when there is a transition A -> B where A != B
	OnExit func(*Event)
	// OnEvent is called when a event occurrs, even if
	// the transition A -> B where A == B.
	// An event can be returned in the case of a transitional state.
	OnEvent func(*Event) *Event
	// contains filtered or unexported fields
}

func NewState

func NewState(name string) *State

func (*State) AddTransition

func (this *State) AddTransition(event string, to *State) *State

AddTransition adds a state transition.

func (*State) Name

func (this *State) Name() string

func (*State) String

func (this *State) String() string

type StateMachine

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

func NewStateMachine

func NewStateMachine(name string) *StateMachine

func (*StateMachine) AdChangeListener

func (this *StateMachine) AdChangeListener(listener func(*Event))

Add a change listener. Is only used to report changes that have already happened. ChangeEvents are only fired AFTER a transition's doAfterTransition is called.

func (*StateMachine) AddState

func (this *StateMachine) AddState(state *State)

AddState adds state to the StateMachine. If it is the first state to be add, it will be the initial state

func (*StateMachine) Event

func (this *StateMachine) Event(name string, data interface{})

func (*StateMachine) SetState

func (this *StateMachine) SetState(state *State, event *Event) *Event

func (*StateMachine) State

func (this *StateMachine) State() *State

func (*StateMachine) String

func (this *StateMachine) String() string

Jump to

Keyboard shortcuts

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