Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterStateMachine ¶
func RegisterStateMachine(sm StateMachine)
Types ¶
type Factory ¶
type Factory interface {
Register(StateMachine)
Get(string) (StateMachine, bool)
}
Factory define the factory interface.
func NewStateFactory ¶
func NewStateFactory() Factory
type SimpleState ¶
type SimpleState struct {
// contains filtered or unexported fields
}
func NewSimpleState ¶
func NewSimpleState(label StateLabel) *SimpleState
func (*SimpleState) Context ¶
func (s *SimpleState) Context() StateContext
func (*SimpleState) Label ¶
func (s *SimpleState) Label() StateLabel
func (*SimpleState) SetContext ¶
func (s *SimpleState) SetContext(context StateContext)
type State ¶
type State interface {
SetContext(StateContext) // set the state context
Context() StateContext
Label() StateLabel // get the state label
}
State define the state interface.
type StateContext ¶
type StateContext interface {
CurrentState() State // get the current state
TransitionTo(State) // transition to the next state
}
StateContext define the state context interface.
type StateMachine ¶
type StateMachine interface {
Name() string // get the state machine name
AddTransition(from, to StateLabel, action Action) error // add a transition
HasTransition(from StateLabel, action Action) bool // check if has transition from one state to another
TransitionToNext(StateContext, Action) bool // transition to the next state
Check() error // Check the completeness of States and Transitions.
RegisterStateBuilder(label StateLabel, state StateBuilder) // register a state
}
StateMachine define the state machine interface.
func GetStateMachine ¶
func GetStateMachine(name string) (StateMachine, bool)
func MustGetStateMachine ¶
func MustGetStateMachine(name string) StateMachine
func NewStateMachine ¶
func NewStateMachine(name string) StateMachine
type TransitionError ¶
type TransitionError struct {
Action Action
Current StateLabel
}
func NewTransitionError ¶
func NewTransitionError(current StateLabel, action Action) *TransitionError
func (*TransitionError) Error ¶
func (te *TransitionError) Error() string
Click to show internal directories.
Click to hide internal directories.