Documentation
¶
Index ¶
- Variables
- type Context
- type Event
- type Planner
- type StateGroup
- func (s *StateGroup) Begin(id interface{}, userState interface{}) error
- func (s *StateGroup) Get(id interface{}) *statestore.StoredState
- func (s *StateGroup) Has(id interface{}) (bool, error)
- func (s *StateGroup) List(out interface{}) error
- func (s *StateGroup) Send(id interface{}, evt interface{}) (err error)
- func (s *StateGroup) Stop(ctx context.Context) error
- type StateHandler
- type StateHandlerWithInit
- type StateMachine
- type TestEvent
- type TestState
Constants ¶
This section is empty.
Variables ¶
var ErrTerminated = xerrors.New("normal shutdown of state machine")
Functions ¶
This section is empty.
Types ¶
type Planner ¶
Planner processes in queue events It returns: 1. a handler of type -- func(ctx Context, st <T>) (func(*<T>), error), where <T> is the typeOf(User) param 2. the number of events processed 3. an error if occured
type StateGroup ¶
type StateGroup struct {
// contains filtered or unexported fields
}
StateGroup manages a group of state machines sharing the same logic
func New ¶
func New(ds datastore.Datastore, hnd StateHandler, stateType interface{}) *StateGroup
stateType: T - (MyStateStruct{})
func (*StateGroup) Begin ¶
func (s *StateGroup) Begin(id interface{}, userState interface{}) error
Begin initiates tracking with a specific value for a given identifier
func (*StateGroup) Get ¶
func (s *StateGroup) Get(id interface{}) *statestore.StoredState
Get gets state for a single state machine
func (*StateGroup) Has ¶
func (s *StateGroup) Has(id interface{}) (bool, error)
Has indicates whether there is data for the given state machine
func (*StateGroup) List ¶
func (s *StateGroup) List(out interface{}) error
List outputs states of all state machines in this group out: *[]StateT
func (*StateGroup) Send ¶
func (s *StateGroup) Send(id interface{}, evt interface{}) (err error)
Send sends an event to machine identified by `id`. `evt` is going to be passed into StateHandler.Planner, in the events[].User param
If a state machine with the specified id doesn't exits, it's created, and it's state is set to zero-value of stateType provided in group constructor
type StateHandler ¶
type StateHandlerWithInit ¶
type StateHandlerWithInit interface { StateHandler Init(<-chan struct{}) }
type StateMachine ¶
type StateMachine struct {
// contains filtered or unexported fields
}