Documentation
¶
Index ¶
- Variables
- func ListStateMachines() []string
- func RegisterStateMachine[S comparable, E comparable, P any](machineId string, stateMachine StateMachine[S, E, P]) error
- func RemoveStateMachine(machineId string) bool
- type Action
- type ActionFunc
- type Condition
- type ConditionFunc
- type DiagramFormat
- type ExternalParallelTransitionBuilder
- type ExternalParallelTransitionBuilderInterface
- type ExternalTransitionBuilderInterface
- type ExternalTransitionsBuilder
- type ExternalTransitionsBuilderInterface
- type FromBuilder
- func (b *FromBuilder[S, E, P, Next]) On(event E) OnInterface[S, E, P]
- func (b *FromBuilder[S, E, P, Next]) Perform(action Action[S, E, P])
- func (b *FromBuilder[S, E, P, Next]) PerformFunc(actionFunc func(from, to S, event E, payload P) error)
- func (b *FromBuilder[S, E, P, Next]) To(state S) ToInterface[S, E, P]
- func (b *FromBuilder[S, E, P, Next]) When(condition Condition[P]) WhenInterface[S, E, P]
- func (b *FromBuilder[S, E, P, Next]) WhenFunc(conditionFunc func(payload P) bool) WhenInterface[S, E, P]
- type FromInterface
- type FromStep
- type InternalTransitionBuilder
- type InternalTransitionBuilderInterface
- type OnInterface
- type OnStep
- type OnTransitionBuilder
- func (b *OnTransitionBuilder[S, E, P, Next]) On(event E) OnInterface[S, E, P]
- func (b *OnTransitionBuilder[S, E, P, Next]) Perform(action Action[S, E, P])
- func (b *OnTransitionBuilder[S, E, P, Next]) PerformFunc(actionFunc func(from, to S, event E, payload P) error)
- func (b *OnTransitionBuilder[S, E, P, Next]) To(state S) ToInterface[S, E, P]
- func (b *OnTransitionBuilder[S, E, P, Next]) When(condition Condition[P]) WhenInterface[S, E, P]
- func (b *OnTransitionBuilder[S, E, P, Next]) WhenFunc(conditionFunc func(payload P) bool) WhenInterface[S, E, P]
- type ParallelFromBuilder
- func (b *ParallelFromBuilder[S, E, P, Next]) On(event E) OnInterface[S, E, P]
- func (b *ParallelFromBuilder[S, E, P, Next]) Perform(action Action[S, E, P])
- func (b *ParallelFromBuilder[S, E, P, Next]) PerformFunc(actionFunc func(from, to S, event E, payload P) error)
- func (b *ParallelFromBuilder[S, E, P, Next]) ToAmong(states ...S) ToInterface[S, E, P]
- func (b *ParallelFromBuilder[S, E, P, Next]) When(condition Condition[P]) WhenInterface[S, E, P]
- func (b *ParallelFromBuilder[S, E, P, Next]) WhenFunc(conditionFunc func(payload P) bool) WhenInterface[S, E, P]
- type ParallelFromInterface
- type PerformStep
- type State
- func (s *State[S, E, P]) AddParallelTransitions(event E, targets []*State[S, E, P], transType TransitionType) []*Transition[S, E, P]
- func (s *State[S, E, P]) AddTransition(event E, target *State[S, E, P], transType TransitionType) *Transition[S, E, P]
- func (s *State[S, E, P]) GetEventTransitions(event E) []*Transition[S, E, P]
- func (s *State[S, E, P]) GetID() S
- type StateMachine
- type StateMachineBuilder
- func (b *StateMachineBuilder[S, E, P]) Build(machineId string) (StateMachine[S, E, P], error)
- func (b *StateMachineBuilder[S, E, P]) ExternalParallelTransition() ExternalParallelTransitionBuilderInterface[S, E, P]
- func (b *StateMachineBuilder[S, E, P]) ExternalTransition() ExternalTransitionBuilderInterface[S, E, P]
- func (b *StateMachineBuilder[S, E, P]) ExternalTransitions() ExternalTransitionsBuilderInterface[S, E, P]
- func (b *StateMachineBuilder[S, E, P]) InternalTransition() InternalTransitionBuilderInterface[S, E, P]
- type StateMachineImpl
- func (sm *StateMachineImpl[S, E, P]) FireEvent(sourceStateId S, event E, payload P) (S, error)
- func (sm *StateMachineImpl[S, E, P]) FireParallelEvent(sourceStateId S, event E, payload P) ([]S, error)
- func (sm *StateMachineImpl[S, E, P]) GenerateDiagram(formats ...DiagramFormat) string
- func (sm *StateMachineImpl[S, E, P]) GetState(stateId S) *State[S, E, P]
- func (sm *StateMachineImpl[S, E, P]) SetReady(ready bool)
- func (sm *StateMachineImpl[S, E, P]) ShowStateMachine() string
- func (sm *StateMachineImpl[S, E, P]) Verify(sourceStateId S, event E) bool
- type ToAmongStep
- type ToInterface
- type ToStep
- type Transition
- type TransitionBuilder
- func (b *TransitionBuilder[S, E, P, Next]) From(state S) FromInterface[S, E, P]
- func (b *TransitionBuilder[S, E, P, Next]) On(event E) OnInterface[S, E, P]
- func (b *TransitionBuilder[S, E, P, Next]) Perform(action Action[S, E, P])
- func (b *TransitionBuilder[S, E, P, Next]) PerformFunc(actionFunc func(from, to S, event E, payload P) error)
- func (b *TransitionBuilder[S, E, P, Next]) To(state S) ToInterface[S, E, P]
- func (b *TransitionBuilder[S, E, P, Next]) When(condition Condition[P]) WhenInterface[S, E, P]
- func (b *TransitionBuilder[S, E, P, Next]) WhenFunc(conditionFunc func(payload P) bool) WhenInterface[S, E, P]
- type TransitionStarterInterface
- type TransitionType
- type WhenInterface
- type WhenStep
- type WithinStep
Constants ¶
This section is empty.
Variables ¶
var ( ErrStateMachineNotFound = errors.New("state machine not found") ErrStateMachineAlreadyExist = errors.New("state machine already exists") ErrStateNotFound = errors.New("state not found") ErrTransitionNotFound = errors.New("no transition found") ErrConditionNotMet = errors.New("transition conditions not met") ErrActionExecutionFailed = errors.New("action execution failed") ErrStateMachineNotReady = errors.New("state machine is not ready yet") ErrInternalTransition = errors.New("internal transition source and target states must be the same") )
Error constants - standard error definitions
Functions ¶
func ListStateMachines ¶
func ListStateMachines() []string
ListStateMachines returns a list of all registered state machine IDs Returns:
Slice of state machine IDs
func RegisterStateMachine ¶
func RegisterStateMachine[S comparable, E comparable, P any](machineId string, stateMachine StateMachine[S, E, P]) error
RegisterStateMachine adds a state machine to the registry Parameters:
machineId: Unique identifier for the state machine stateMachine: State machine instance to register
Returns:
Error if a state machine with the same ID already exists
func RemoveStateMachine ¶
RemoveStateMachine removes a state machine from the registry Parameters:
machineId: Unique identifier for the state machine to remove
Returns:
True if the state machine was found and removed, false otherwise
Types ¶
type Action ¶
type Action[S comparable, E comparable, P any] interface { // Execute runs the action during a state transition Execute(from, to S, event E, payload P) error }
Action is an interface for transition actions
type ActionFunc ¶
type ActionFunc[S comparable, E comparable, P any] func(from, to S, event E, payload P) error
ActionFunc is a function type that implements Action interface
func (ActionFunc[S, E, P]) Execute ¶
func (f ActionFunc[S, E, P]) Execute(from, to S, event E, payload P) error
Execute implements Action interface
type Condition ¶
type Condition[P any] interface { // IsSatisfied returns true if the condition is met IsSatisfied(payload P) bool }
Condition is an interface for transition conditions
type ConditionFunc ¶
ConditionFunc is a function type that implements Condition interface
func (ConditionFunc[P]) IsSatisfied ¶
func (f ConditionFunc[P]) IsSatisfied(payload P) bool
IsSatisfied implements Condition interface
type DiagramFormat ¶
type DiagramFormat int
DiagramFormat defines the supported diagram formats
const ( // PlantUML format for UML diagrams PlantUML DiagramFormat = iota // MarkdownTable format for tabular representation MarkdownTable // MarkdownFlowchart format for flowcharts MarkdownFlowchart // MarkdownStateDiagram format for Mermaid state diagrams MarkdownStateDiagram )
type ExternalParallelTransitionBuilder ¶
type ExternalParallelTransitionBuilder[S comparable, E comparable, P any] struct { // contains filtered or unexported fields }
ExternalParallelTransitionBuilder builds external parallel transitions
func (*ExternalParallelTransitionBuilder[S, E, P]) From ¶
func (b *ExternalParallelTransitionBuilder[S, E, P]) From(state S) ParallelFromInterface[S, E, P]
From specifies the source state Parameters:
state: Source state
Returns:
The parallel from builder for method chaining
type ExternalParallelTransitionBuilderInterface ¶
type ExternalParallelTransitionBuilderInterface[S comparable, E comparable, P any] interface { // From specifies the source state From(state S) ParallelFromInterface[S, E, P] }
ExternalParallelTransitionBuilderInterface is the interface for building external parallel transitions
type ExternalTransitionBuilderInterface ¶
type ExternalTransitionBuilderInterface[S comparable, E comparable, P any] interface { // From specifies the source state From(state S) FromInterface[S, E, P] }
ExternalTransitionBuilderInterface is the interface for building external transitions
type ExternalTransitionsBuilder ¶
type ExternalTransitionsBuilder[S comparable, E comparable, P any] struct { // contains filtered or unexported fields }
ExternalTransitionsBuilder builds external transitions from multiple source states to a single target state
func (*ExternalTransitionsBuilder[S, E, P]) FromAmong ¶
func (b *ExternalTransitionsBuilder[S, E, P]) FromAmong(states ...S) FromInterface[S, E, P]
FromAmong specifies multiple source states Parameters:
states: Multiple source states
Returns:
The from builder for method chaining
type ExternalTransitionsBuilderInterface ¶
type ExternalTransitionsBuilderInterface[S comparable, E comparable, P any] interface { // FromAmong specifies multiple source states FromAmong(states ...S) FromInterface[S, E, P] }
ExternalTransitionsBuilderInterface is the interface for building multiple external transitions
type FromBuilder ¶
type FromBuilder[S comparable, E comparable, P any, Next any] struct { // contains filtered or unexported fields }
FromBuilder builds the "from" part of multiple transitions
func (*FromBuilder[S, E, P, Next]) On ¶
func (b *FromBuilder[S, E, P, Next]) On(event E) OnInterface[S, E, P]
On specifies the triggering event Parameters:
event: The event that triggers these transitions
Returns:
The from builder for method chaining
func (*FromBuilder[S, E, P, Next]) Perform ¶
func (b *FromBuilder[S, E, P, Next]) Perform(action Action[S, E, P])
Perform specifies the action to execute during all transitions Parameters:
action: The action to execute when the transitions occur
func (*FromBuilder[S, E, P, Next]) PerformFunc ¶
func (b *FromBuilder[S, E, P, Next]) PerformFunc(actionFunc func(from, to S, event E, payload P) error)
PerformFunc specifies a function as the action to execute during all transitions Parameters:
actionFunc: The function to execute when the transitions occur
func (*FromBuilder[S, E, P, Next]) To ¶
func (b *FromBuilder[S, E, P, Next]) To(state S) ToInterface[S, E, P]
To specifies the target state Parameters:
state: Target state
Returns:
The from builder for method chaining
func (*FromBuilder[S, E, P, Next]) When ¶
func (b *FromBuilder[S, E, P, Next]) When(condition Condition[P]) WhenInterface[S, E, P]
When specifies the condition for all transitions Parameters:
condition: The condition that must be satisfied for the transitions to occur
Returns:
The from builder for method chaining
func (*FromBuilder[S, E, P, Next]) WhenFunc ¶
func (b *FromBuilder[S, E, P, Next]) WhenFunc(conditionFunc func(payload P) bool) WhenInterface[S, E, P]
WhenFunc specifies a function as the condition for all transitions Parameters:
conditionFunc: The function that must return true for the transitions to occur
Returns:
The from builder for method chaining
type FromInterface ¶
type FromInterface[S comparable, E comparable, P any] interface { // To specifies the target state To(state S) ToInterface[S, E, P] }
FromInterface is the interface for specifying the source state of a transition
type FromStep ¶
type FromStep interface{}
FromStep Step marker interfaces to enforce the correct order of method calls
type InternalTransitionBuilder ¶
type InternalTransitionBuilder[S comparable, E comparable, P any] struct { // contains filtered or unexported fields }
InternalTransitionBuilder builds internal transitions
func (*InternalTransitionBuilder[S, E, P]) Within ¶
func (b *InternalTransitionBuilder[S, E, P]) Within(state S) ToInterface[S, E, P]
Within specifies the state where the internal transition occurs Parameters:
state: The state where the internal transition occurs
Returns:
The internal transition builder for method chaining
type InternalTransitionBuilderInterface ¶
type InternalTransitionBuilderInterface[S comparable, E comparable, P any] interface { // Within specifies the state where the internal transition occurs Within(state S) ToInterface[S, E, P] }
InternalTransitionBuilderInterface is the interface for building internal transitions
type OnInterface ¶
type OnInterface[S comparable, E comparable, P any] interface { // When specifies the condition for the transition When(condition Condition[P]) WhenInterface[S, E, P] // WhenFunc specifies a function as the condition for the transition WhenFunc(conditionFunc func(payload P) bool) WhenInterface[S, E, P] }
OnInterface is the interface for specifying the triggering event of a transition
type OnTransitionBuilder ¶
type OnTransitionBuilder[S comparable, E comparable, P any, Next any] struct { // contains filtered or unexported fields }
OnTransitionBuilder builds the "on" part of an internal transition
func (*OnTransitionBuilder[S, E, P, Next]) On ¶
func (b *OnTransitionBuilder[S, E, P, Next]) On(event E) OnInterface[S, E, P]
On specifies the triggering event Parameters:
event: The event that triggers this transition
Returns:
The on transition builder for method chaining
func (*OnTransitionBuilder[S, E, P, Next]) Perform ¶
func (b *OnTransitionBuilder[S, E, P, Next]) Perform(action Action[S, E, P])
Perform specifies the action to execute during the transition Parameters:
action: The action to execute when the transition occurs
func (*OnTransitionBuilder[S, E, P, Next]) PerformFunc ¶
func (b *OnTransitionBuilder[S, E, P, Next]) PerformFunc(actionFunc func(from, to S, event E, payload P) error)
PerformFunc specifies a function as the action to execute during the transition Parameters:
actionFunc: The function to execute when the transition occurs
func (*OnTransitionBuilder[S, E, P, Next]) To ¶
func (b *OnTransitionBuilder[S, E, P, Next]) To(state S) ToInterface[S, E, P]
To specifies the target state Parameters:
state: Target state
Returns:
The on transition builder for method chaining
func (*OnTransitionBuilder[S, E, P, Next]) When ¶
func (b *OnTransitionBuilder[S, E, P, Next]) When(condition Condition[P]) WhenInterface[S, E, P]
When specifies the condition for the transition Parameters:
condition: The condition that must be satisfied for the transition to occur
Returns:
The on transition builder for method chaining
func (*OnTransitionBuilder[S, E, P, Next]) WhenFunc ¶
func (b *OnTransitionBuilder[S, E, P, Next]) WhenFunc(conditionFunc func(payload P) bool) WhenInterface[S, E, P]
WhenFunc specifies a function as the condition for the transition Parameters:
conditionFunc: The function that must return true for the transition to occur
Returns:
The on transition builder for method chaining
type ParallelFromBuilder ¶
type ParallelFromBuilder[S comparable, E comparable, P any, Next any] struct { // contains filtered or unexported fields }
ParallelFromBuilder builds the "from" part of a parallel transition
func (*ParallelFromBuilder[S, E, P, Next]) On ¶
func (b *ParallelFromBuilder[S, E, P, Next]) On(event E) OnInterface[S, E, P]
On specifies the triggering event Parameters:
event: The event that triggers these transitions
Returns:
The parallel from builder for method chaining
func (*ParallelFromBuilder[S, E, P, Next]) Perform ¶
func (b *ParallelFromBuilder[S, E, P, Next]) Perform(action Action[S, E, P])
Perform specifies the action to execute during all transitions Parameters:
action: The action to execute when the transitions occur
func (*ParallelFromBuilder[S, E, P, Next]) PerformFunc ¶
func (b *ParallelFromBuilder[S, E, P, Next]) PerformFunc(actionFunc func(from, to S, event E, payload P) error)
PerformFunc specifies a function as the action to execute during all transitions Parameters:
actionFunc: The function to execute when the transitions occur
func (*ParallelFromBuilder[S, E, P, Next]) ToAmong ¶
func (b *ParallelFromBuilder[S, E, P, Next]) ToAmong(states ...S) ToInterface[S, E, P]
ToAmong specifies multiple target states Parameters:
states: Multiple target states
Returns:
The parallel from builder for method chaining
func (*ParallelFromBuilder[S, E, P, Next]) When ¶
func (b *ParallelFromBuilder[S, E, P, Next]) When(condition Condition[P]) WhenInterface[S, E, P]
When specifies the condition for all transitions Parameters:
condition: The condition that must be satisfied for the transitions to occur
Returns:
The parallel from builder for method chaining
func (*ParallelFromBuilder[S, E, P, Next]) WhenFunc ¶
func (b *ParallelFromBuilder[S, E, P, Next]) WhenFunc(conditionFunc func(payload P) bool) WhenInterface[S, E, P]
WhenFunc specifies a function as the condition for all transitions Parameters:
conditionFunc: The function that must return true for the transitions to occur
Returns:
The parallel from builder for method chaining
type ParallelFromInterface ¶
type ParallelFromInterface[S comparable, E comparable, P any] interface { // ToAmong specifies multiple target states ToAmong(states ...S) ToInterface[S, E, P] }
ParallelFromInterface is the interface for specifying the source state of a parallel transition
type PerformStep ¶
type PerformStep interface{}
type State ¶
type State[S comparable, E comparable, P any] struct { // contains filtered or unexported fields }
State represents a state in the state machine
func NewState ¶
func NewState[S comparable, E comparable, P any](id S) *State[S, E, P]
NewState creates a new state
func (*State[S, E, P]) AddParallelTransitions ¶
func (s *State[S, E, P]) AddParallelTransitions(event E, targets []*State[S, E, P], transType TransitionType) []*Transition[S, E, P]
AddParallelTransitions adds multiple transitions for the same event to different target states
func (*State[S, E, P]) AddTransition ¶
func (s *State[S, E, P]) AddTransition(event E, target *State[S, E, P], transType TransitionType) *Transition[S, E, P]
AddTransition adds a transition to this state
func (*State[S, E, P]) GetEventTransitions ¶
func (s *State[S, E, P]) GetEventTransitions(event E) []*Transition[S, E, P]
GetEventTransitions returns all transitions for a given event
type StateMachine ¶
type StateMachine[S comparable, E comparable, P any] interface { // FireEvent triggers a state transition based on the current state and event // Returns the new state and any error that occurred FireEvent(sourceState S, event E, payload P) (S, error) // FireParallelEvent triggers parallel state transitions based on the current state and event // Returns a slice of new states and any error that occurred FireParallelEvent(sourceState S, event E, payload P) ([]S, error) // Verify checks if there is a valid transition for the given state and event // Returns true if a transition exists, false otherwise Verify(sourceState S, event E) bool // ShowStateMachine returns a string representation of the state machine ShowStateMachine() string // GenerateDiagram returns a diagram of the state machine in the specified formats // If formats is nil or empty, defaults to PlantUML // If multiple formats are provided, returns all requested formats concatenated GenerateDiagram(formats ...DiagramFormat) string }
StateMachine is a generic state machine interface S: State type, must be comparable (e.g., string, int) E: Event type, must be comparable P: Payload type, can be any type, used to pass data during state transitions
func GetStateMachine ¶
func GetStateMachine[S comparable, E comparable, P any](machineId string) (StateMachine[S, E, P], error)
GetStateMachine retrieves a state machine by ID Parameters:
machineId: Unique identifier for the state machine to retrieve
Returns:
The state machine instance and error if not found or type mismatch
type StateMachineBuilder ¶
type StateMachineBuilder[S comparable, E comparable, P any] struct { // contains filtered or unexported fields }
StateMachineBuilder builds state machines with a fluent API
func NewStateMachineBuilder ¶
func NewStateMachineBuilder[S comparable, E comparable, P any]() *StateMachineBuilder[S, E, P]
NewStateMachineBuilder creates a new builder Returns:
A new state machine builder instance
func (*StateMachineBuilder[S, E, P]) Build ¶
func (b *StateMachineBuilder[S, E, P]) Build(machineId string) (StateMachine[S, E, P], error)
Build finalizes the state machine with the given ID Parameters:
machineId: Unique identifier for the state machine
Returns:
The built state machine and possible error
func (*StateMachineBuilder[S, E, P]) ExternalParallelTransition ¶
func (b *StateMachineBuilder[S, E, P]) ExternalParallelTransition() ExternalParallelTransitionBuilderInterface[S, E, P]
ExternalParallelTransition starts defining an external parallel transition Returns:
A external parallel transition builder for configuring the parallel transition
func (*StateMachineBuilder[S, E, P]) ExternalTransition ¶
func (b *StateMachineBuilder[S, E, P]) ExternalTransition() ExternalTransitionBuilderInterface[S, E, P]
ExternalTransition starts defining an external transition Returns:
A transition builder for configuring the external transition
func (*StateMachineBuilder[S, E, P]) ExternalTransitions ¶
func (b *StateMachineBuilder[S, E, P]) ExternalTransitions() ExternalTransitionsBuilderInterface[S, E, P]
ExternalTransitions starts defining multiple external transitions from different source states to the same target state Returns:
A external transitions builder for configuring the transitions
func (*StateMachineBuilder[S, E, P]) InternalTransition ¶
func (b *StateMachineBuilder[S, E, P]) InternalTransition() InternalTransitionBuilderInterface[S, E, P]
InternalTransition starts defining an internal transition Returns:
A internal transition builder for configuring the internal transition
type StateMachineImpl ¶
type StateMachineImpl[S comparable, E comparable, P any] struct { // contains filtered or unexported fields }
StateMachineImpl implements the StateMachine interface
func (*StateMachineImpl[S, E, P]) FireEvent ¶
func (sm *StateMachineImpl[S, E, P]) FireEvent(sourceStateId S, event E, payload P) (S, error)
FireEvent triggers a state transition based on the current state and event
func (*StateMachineImpl[S, E, P]) FireParallelEvent ¶
func (sm *StateMachineImpl[S, E, P]) FireParallelEvent(sourceStateId S, event E, payload P) ([]S, error)
FireParallelEvent triggers parallel state transitions based on the current state and event
func (*StateMachineImpl[S, E, P]) GenerateDiagram ¶
func (sm *StateMachineImpl[S, E, P]) GenerateDiagram(formats ...DiagramFormat) string
GenerateDiagram returns a diagram of the state machine in the specified formats If formats is nil or empty, defaults to PlantUML If multiple formats are provided, returns all requested formats concatenated
func (*StateMachineImpl[S, E, P]) GetState ¶
func (sm *StateMachineImpl[S, E, P]) GetState(stateId S) *State[S, E, P]
GetState returns a state by ID, creating it if it doesn't exist
func (*StateMachineImpl[S, E, P]) SetReady ¶
func (sm *StateMachineImpl[S, E, P]) SetReady(ready bool)
SetReady marks the state machine as ready
func (*StateMachineImpl[S, E, P]) ShowStateMachine ¶
func (sm *StateMachineImpl[S, E, P]) ShowStateMachine() string
ShowStateMachine returns a string representation of the state machine
func (*StateMachineImpl[S, E, P]) Verify ¶
func (sm *StateMachineImpl[S, E, P]) Verify(sourceStateId S, event E) bool
Verify checks if there is a valid transition for the given state and event
type ToAmongStep ¶
type ToAmongStep interface{}
type ToInterface ¶
type ToInterface[S comparable, E comparable, P any] interface { // On specifies the triggering event On(event E) OnInterface[S, E, P] }
ToInterface is the interface for specifying the target state of a transition
type Transition ¶
type Transition[S comparable, E comparable, P any] struct { Source *State[S, E, P] Target *State[S, E, P] Event E Condition Condition[P] Action Action[S, E, P] TransType TransitionType }
Transition represents a state transition
type TransitionBuilder ¶
type TransitionBuilder[S comparable, E comparable, P any, Next any] struct { // contains filtered or unexported fields }
TransitionBuilder builds individual transitions
func (*TransitionBuilder[S, E, P, Next]) From ¶
func (b *TransitionBuilder[S, E, P, Next]) From(state S) FromInterface[S, E, P]
From specifies the source state Parameters:
state: Source state
Returns:
The transition builder for method chaining
func (*TransitionBuilder[S, E, P, Next]) On ¶
func (b *TransitionBuilder[S, E, P, Next]) On(event E) OnInterface[S, E, P]
On specifies the triggering event Parameters:
event: The event that triggers this transition
Returns:
The transition builder for method chaining
func (*TransitionBuilder[S, E, P, Next]) Perform ¶
func (b *TransitionBuilder[S, E, P, Next]) Perform(action Action[S, E, P])
Perform specifies the action to execute during the transition Parameters:
action: The action to execute when the transition occurs
func (*TransitionBuilder[S, E, P, Next]) PerformFunc ¶
func (b *TransitionBuilder[S, E, P, Next]) PerformFunc(actionFunc func(from, to S, event E, payload P) error)
PerformFunc specifies a function as the action to execute during the transition Parameters:
actionFunc: The function to execute when the transition occurs
func (*TransitionBuilder[S, E, P, Next]) To ¶
func (b *TransitionBuilder[S, E, P, Next]) To(state S) ToInterface[S, E, P]
To specifies the target state Parameters:
state: Target state
Returns:
The transition builder for method chaining
func (*TransitionBuilder[S, E, P, Next]) When ¶
func (b *TransitionBuilder[S, E, P, Next]) When(condition Condition[P]) WhenInterface[S, E, P]
When specifies the condition for the transition Parameters:
condition: The condition that must be satisfied for the transition to occur
Returns:
The transition builder for method chaining
func (*TransitionBuilder[S, E, P, Next]) WhenFunc ¶
func (b *TransitionBuilder[S, E, P, Next]) WhenFunc(conditionFunc func(payload P) bool) WhenInterface[S, E, P]
WhenFunc specifies a function as the condition for the transition Parameters:
conditionFunc: The function that must return true for the transition to occur
Returns:
The transition builder for method chaining
type TransitionStarterInterface ¶
type TransitionStarterInterface[S comparable, E comparable, P any] interface { // ExternalTransition starts defining an external transition ExternalTransition() ExternalTransitionBuilderInterface[S, E, P] // InternalTransition starts defining an internal transition InternalTransition() InternalTransitionBuilderInterface[S, E, P] // ExternalTransitions starts defining multiple external transitions ExternalTransitions() ExternalTransitionsBuilderInterface[S, E, P] // ExternalParallelTransition starts defining an external parallel transition ExternalParallelTransition() ExternalParallelTransitionBuilderInterface[S, E, P] }
TransitionStarterInterface is the interface for starting a transition definition
type TransitionType ¶
type TransitionType int
TransitionType defines the type of transition
const ( // External transitions change the state from source to target External TransitionType = iota // Internal transitions don't change the state Internal )
type WhenInterface ¶
type WhenInterface[S comparable, E comparable, P any] interface { // Perform specifies the action to execute during the transition Perform(action Action[S, E, P]) // PerformFunc specifies a function as the action to execute during the transition PerformFunc(actionFunc func(from, to S, event E, payload P) error) }
WhenInterface is the interface for specifying the condition of a transition
type WithinStep ¶
type WithinStep interface{}