Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func TransitionTo ¶
func TransitionTo[S FiniteState](inputs ...func(context.Context, S)) *transition[S]
TransitionTo returns a transition to the next state, with optional inputs feeding into next state.
func WithBackOff ¶
func WithBackOff(t Transition, backOff backoff.BackOff) *transitionWithBackOff
WithBackOff delays the transition.
Types ¶
type FiniteState ¶
type FiniteState interface { IsTerminal() bool // IsTerminal returns true if the state is a terminal (end) state Do(context.Context) Transition // Do returns the next transition }
FiniteState is a state in Finite-State-Machine
type StateMachine ¶
type StateMachine struct { Maps map[reflect.Type]FiniteState clock.Clock }
StateMachine is a Finite-State-Machine (FSM) that starts from a given state, Do() the state, and then transition to the next state until terminal state is reached.
Please use one struct type to represent one FiniteState.
func MustNewStateMachine ¶
func MustNewStateMachine(states ...FiniteState) *StateMachine
func NewStateMachine ¶
func NewStateMachine(states ...FiniteState) (*StateMachine, error)
func (*StateMachine) Start ¶
func (sm *StateMachine) Start(ctx context.Context, state FiniteState) (FiniteState, error)
type Transition ¶
Transition decides the next state to hop
type TransitionWithBackOff ¶
type TransitionWithBackOff interface { Transition GetBackOff() backoff.BackOff }
Click to show internal directories.
Click to hide internal directories.