Documentation ¶
Index ¶
- type Action
- type Clock
- type Expiry
- type Flap
- type ID
- type Index
- type Instance
- type Limit
- type Options
- type Set
- func (s *Set) Add(initial Index) Instance
- func (s *Set) CountByState(state Index) int
- func (s *Set) Delete(instance Instance)
- func (s *Set) ForEachInstance(view func(ID, Index, interface{}) bool)
- func (s *Set) ForEachInstanceInState(check Index, view func(ID, Index, interface{}) bool)
- func (s *Set) Instance(id ID) Instance
- func (s *Set) Signal(signal Signal, instance ID, optionalData ...interface{}) error
- func (s *Set) Size() int
- func (s *Set) Stop()
- type Signal
- type Spec
- type State
- type Tick
- type Time
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Action ¶
Action is the action to take when a signal is received, prior to transition to the next state. The error returned by the function is an exception which will put the state machine in an error state. This error state is not the same as some application-specific error state which is a state defined to correspond to some external event indicating a real-world error event (as opposed to a programming error here).
type Clock ¶
type Clock struct { C <-chan Tick // contains filtered or unexported fields }
Clock adapts a timer tick
type Expiry ¶
Expiry specifies the rule for TTL.. A state can have TTL / deadline that when it expires a signal can be raised.
type Flap ¶
Flap is oscillation between two adjacent states. For example, a->b followed by b->a is counted as 1 flap. Similarly, b->a followed by a->b is another flap.
type Instance ¶
type Instance interface { // ID returns the ID of the instance ID() ID // State returns the state of the instance. This is an expensive call to be submitted to queue to view State() Index // Data returns the custom data attached to the instance. It's set via the optional arg in Signal Data() interface{} // Signal signals the instance with optional custom data Signal(Signal, ...interface{}) error // CanReceive returns true if the current state of the instance can receive the given signal CanReceive(Signal) bool }
Instance is the interface that returns ID and state of the fsm instance safely.
type Options ¶
type Options struct { // Name is the name of the set Name string // BufferSize is the size of transaction queue/buffered channel BufferSize int }
Options contains options for the set
func DefaultOptions ¶
DefaultOptions returns default values
type Set ¶
type Set struct {
// contains filtered or unexported fields
}
Set is a collection of fsm instances that follow a given spec. This is the primary interface to manipulate the instances... by sending signals to it via channels.
func (*Set) CountByState ¶
CountByState returns a count of instances in a given state.
func (*Set) ForEachInstance ¶
ForEachInstance iterates through the set and provides a consistent view of the instances
func (*Set) ForEachInstanceInState ¶
ForEachInstanceInState iterates through the set and provides a consistent view of the instances
type Signal ¶
type Signal int
Signal is a signal that can drive the state machine to transfer from one state to next.
type Spec ¶
type Spec struct {
// contains filtered or unexported fields
}
Spec is a specification of all the rules for the fsm
func (*Spec) CheckFlapping ¶
CheckFlapping - Limit is the maximum of a->b b->a transitions allowable. For detecting oscillations between two adjacent states (no hops)
func (*Spec) CheckFlappingMust ¶
CheckFlappingMust is a Must version (will panic if err) of CheckFlapping
type State ¶
type State struct { // Index is a unique key of the state Index Index // Transitions fully specifies all the possible transitions from this state, by the way of signals. Transitions map[Signal]Index // Actions specify for each signal, what code / action is to be executed as the fsm transits from one state to next. Actions map[Signal]Action // Errors specifies the handling of errors when executing action. On action error, the mapped state is transitioned. Errors map[Signal]Index // TTL specifies how long this state can last before a signal is raised. TTL Expiry // Visit specifies a limit on the number of times the fsm can visit this state before raising a signal. Visit Limit }
State encapsulates all the possible transitions and actions to perform during the state transition. A state can have a TTL so that it is allowed to be in that state for a given TTL. On expiration, a signal is raised.