Documentation
¶
Index ¶
- type Callback
- type Callbacks
- type Export
- type FSM
- func (f *FSM) AddCallback(state State, typeCb string, cb func(*FSM)) error
- func (f *FSM) AddEvent(name State, dst State) error
- func (f *FSM) AddStateTransitionRules(src State, dst ...State) error
- func (f *FSM) Export() Export
- func (f *FSM) ExportFunc(exec func(Export, interface{}) interface{}, args interface{}) interface{}
- func (f *FSM) GetCurrentState() State
- func (f *FSM) Import(data Export) error
- func (f *FSM) MarshalJSON() ([]byte, error)
- func (f *FSM) SendEvent(event State) error
- func (f *FSM) SetStateTransition(toState State) error
- func (f *FSM) UnmarshalJSON(data []byte) error
- type Init
- type State
- type TransitionRuleSet
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Callback ¶
type Callback func(*FSM)
Callback is a function type that callbacks should use. Event is the current event info as the callback happenf.
type Callbacks ¶
type Callbacks struct {
// contains filtered or unexported fields
}
Callbaks is a shorthand for defining the callbacks in FSM
type Export ¶
type Export struct {
// current is the state that the FSM is currently in.
State State
// transitions maps events and source states to destination statef.
Transitions map[State]TransitionRuleSet
Events map[State]State
// callbacks maps events and source states to destination statef.
Callbacks Callbacks
}
Export this FSM type for export data
type FSM ¶
type FSM struct {
// contains filtered or unexported fields
}
FSM is the state machine that holds the current state.
func (*FSM) AddCallback ¶
AddCallback is a function for adding callback function by event
func (*FSM) AddStateTransitionRules ¶
AddStateTransitionRules is a function for adding valid state transitions to the machine. This allows you to define whicj states any given state can be transitioned to.
func (*FSM) ExportFunc ¶
func (*FSM) GetCurrentState ¶
GetCurrentState returns the current state. If the State returned is "", then the machine has not been given an initial state.
func (*FSM) MarshalJSON ¶
func (*FSM) SetStateTransition ¶
SetStateTransition triggers a transition to the toState. This function is also used to set the initial stte of machine.
Before you can transition to any state, even for the initial, you stateMust define it with AddStateTransitionRules(). If you are setting the initial state, and that state is not define, this will return an ErrInvalidInitialState error.
When transitiong from a state, this function will return an error either if the state transition is not allowed, or if the destination state has not been defined. In both cases, it's seen as a non-permitted state transition.
func (*FSM) UnmarshalJSON ¶
type Init ¶
type Init interface {
Export() string
Import(FSM) error
// TODO: add work with channels (input/output)
Watch() chan<- interface{}
Listen(<-chan interface{})
}
Import/Export TODO: use DI instead struct Export
type TransitionRuleSet ¶
type TransitionRuleSet map[State]struct{}
TransitionRuleSet is a set of allowed transitionf. This uses map of struct{} to implement a set.