Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrEventRejected = errors.New("event rejected")
ErrEventRejected is the error returned when the state machine cannot process an event in the state that it is in.
Functions ¶
This section is empty.
Types ¶
type Event ¶
type Event string
Event represents an extensible event type in the state machine.
const ( // NoOp represents a no-op event. State machine stops when this event is emitted. NoOp Event = "NoOp" )
type StateMachine ¶
type StateMachine struct {
// contains filtered or unexported fields
}
StateMachine represents the state machine.
func New ¶
func New(state State, stateTransitions StateTransitions, hook Hook) *StateMachine
New returns initialized state machine.
func (*StateMachine) Current ¶
func (s *StateMachine) Current() State
Current return current state machine state.
func (*StateMachine) Transition ¶
func (s *StateMachine) Transition(ctx context.Context) error
Transition triggers current state action and sends event to the state machine.
type StateTransitions ¶
type StateTransitions map[State]Transition
StateTransitions represents a mapping of states and their implementations.
type Transition ¶
Transition binds a state with an action and a set of events it can handle.
Click to show internal directories.
Click to hide internal directories.