Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var (
InvalidTransition = errors.New("invalid transition")
)
Functions ¶
func WithSubject ¶
WithSubject is intended to be passed to New to set the Subject
Types ¶
type Guard ¶
Guard provides protection against transitioning to the goal State. Returning true/false indicates if the transition is permitted or not.
type Machine ¶
Machine is a pairing of Rules and a Subject. The subject or rules may be changed at any time within the machine's lifecycle.
func (Machine) Transition ¶
Transition attempts to move the Subject to the Goal state.
type Ruleset ¶
type Ruleset map[Transition][]Guard
Ruleset stores the rules for the state machine.
func CreateRuleset ¶
func CreateRuleset(transitions ...Transition) Ruleset
CreateRuleset will establish a ruleset with the provided transitions. This eases initialization when storing within another structure.
func (Ruleset) AddRule ¶
func (r Ruleset) AddRule(t Transition, guards ...Guard)
AddRule adds Guards for the given Transition
func (Ruleset) AddTransition ¶
func (r Ruleset) AddTransition(t Transition)
AddTransition adds a transition with a default rule
type Stater ¶
Stater can be passed into the FSM. The Stater is reponsible for setting its own default state. Behavior of a Stater without a State is undefined.
type T ¶
type T struct {
O, E State
}
T implements the Transition interface; it provides a default implementation of a Transition.
type Transition ¶
Transition is the change between States