Documentation
¶
Overview ¶
Package statemachine provides a generic finite state machine with callbacks.
Index ¶
- type Callback
- type Machine
- func (m *Machine) GetState(resourceID string) (string, error)
- func (m *Machine) OnTransition(cb Callback)
- func (m *Machine) Remove(resourceID string)
- func (m *Machine) Resources() map[string]string
- func (m *Machine) SetState(resourceID, state string)
- func (m *Machine) String(resourceID string) string
- func (m *Machine) Transition(resourceID, to string) error
- type Transition
- type TransitionMap
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Callback ¶
type Callback func(resourceID, from, to string)
Callback is called when a state transition occurs.
type Machine ¶
type Machine struct {
// contains filtered or unexported fields
}
Machine is a generic finite state machine.
func New ¶
func New(transitions []Transition) *Machine
New creates a new Machine with the given legal transitions.
func (*Machine) OnTransition ¶
OnTransition registers a callback for state transitions.
func (*Machine) Transition ¶
Transition attempts to transition a resource to a new state.
type Transition ¶
Transition defines a legal state transition.
type TransitionMap ¶
TransitionMap holds legal transitions indexed by "from" state.
func NewTransitionMap ¶
func NewTransitionMap(transitions []Transition) TransitionMap
NewTransitionMap creates a TransitionMap from a list of transitions.
func (TransitionMap) IsAllowed ¶
func (tm TransitionMap) IsAllowed(from, to string) bool
IsAllowed checks if a transition from one state to another is legal.
Click to show internal directories.
Click to hide internal directories.