Back to godoc.org

Package fsm

v0.0.1
Latest Go to latest

The highest tagged major version is .

Published: Dec 5, 2019 | License: BSD-2-Clause | Module: github.com/quintans/toolkit

Index

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

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier