Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithSubject ¶
WithSubject is intended to be passed to New to set the Subject
Types ¶
type ErrInvalidTransition ¶
type ErrInvalidTransition struct {
Transition
}
ErrInvalidTransition is returned when no transition is defined between
func (ErrInvalidTransition) Error ¶
func (e ErrInvalidTransition) Error() string
Error returns ErrInvalidTransition error message
type Guard ¶
Guard provides protection against transitioning to the goal State. Returning an error or nil 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
func (Ruleset) IsValidTransition ¶
IsValidTransition determines if a transition is allowed. This occurs in parallel. NOTE: Guards are not halted if they are short-circuited for some transition. They may continue running *after* the outcome is determined. Returns a list of errors if the transition is invalid or nil otherwise
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