Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FSM ¶
type FSM struct { Transitions []*Transition // contains filtered or unexported fields }
FSM is a finite state machine. Transitions is a list of valid state transitions. The initial state is the empty string, and transitions must include at least one transition from this initial state. If multiple transitions exist for the same From-To pair then each of the corresponding actions will be taken in the order the appaer in the list.
func (*FSM) Goto ¶
Goto transitions to the new state given and calls the associated action callback if there is one. The callback takes place after the current and previous states have been updated. If the given state is not a valid transition then an error is returned. If the given state is the current state then this function does nothing.
func (*FSM) Previous ¶
Previous returns the previous state. This will be initally be equal to the current state (the empty string), until the state has changed at least once.
func (*FSM) ValidTransitions ¶
ValidTransitions returns a list of valid states that can be transitioned to from the given state.
type State ¶
type State string
State is the name of a state in the finite state machine.
const ( // InitialState is the initial state that an FSM is in. InitialState State = "" )
type Transition ¶
type Transition struct {
From, To State
Action func()
}
Transition defines what action to take when transitioning between the states From and To.