Documentation
¶
Index ¶
- Constants
- type DefaultDelegate
- type Delegate
- type Error
- type EventProcessor
- type StateMachine
- func (m *StateMachine) Export(outfile string) error
- func (m *StateMachine) ExportWithDetails(outfile string, format string, layout string, scale string, more string) error
- func (m *StateMachine) GetState() string
- func (m *StateMachine) LastingTime() time.Duration
- func (m *StateMachine) Reset()
- func (m *StateMachine) Trigger(currentState string, event string) error
- type StateType
- type Transition
Constants ¶
View Source
const PreStatusKeepSize = 20
PreStatusKeepSize Size of history status.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DefaultDelegate ¶
type DefaultDelegate struct {
P EventProcessor
}
DefaultDelegate is a default delegate.
func (*DefaultDelegate) HandleEvent ¶
func (dd *DefaultDelegate) HandleEvent(action string, fromState string, toState string) error
HandleEvent implements Delegate interface and split HandleEvent into three actions
type EventProcessor ¶
type EventProcessor interface {
// OnExit Action handles exiting a state
OnExit(fromState string)
// Action is used to handle transitions
Action(action string, fromState string, toState string) error
// OnActionFailure failed to execute the Action
OnActionFailure(action string, fromState string, toState string, err error)
// OnExit Action handles entering a state
OnEnter(toState string)
}
EventProcessor defines OnExit, Action and OnEnter actions
type StateMachine ¶
type StateMachine struct {
sync.Mutex
State StateType `json:"state"`
PreState []StateType `json:"preState"`
Transitions []Transition `json:"transitions"`
// contains filtered or unexported fields
}
StateMachine is a FSM that can handle transitions
func NewStateMachine ¶
func NewStateMachine(defaultState string, delegate Delegate, transitions ...Transition) *StateMachine
NewStateMachine creates a new state machine.
func (*StateMachine) Export ¶
func (m *StateMachine) Export(outfile string) error
Export exports the state diagram into a file
func (*StateMachine) ExportWithDetails ¶
func (m *StateMachine) ExportWithDetails(outfile string, format string, layout string, scale string, more string) error
ExportWithDetails exports the state diagram with more graphviz options
func (*StateMachine) LastingTime ¶
func (m *StateMachine) LastingTime() time.Duration
LastingTime return current status lasting time.
Click to show internal directories.
Click to hide internal directories.