statemachine

package
v0.2.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 20, 2020 License: Apache-2.0, MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context struct {
	// contains filtered or unexported fields
}

func (*Context) Context

func (ctx *Context) Context() context.Context

func (*Context) Send

func (ctx *Context) Send(evt interface{}) error

type Event

type Event struct {
	User interface{}
}

type Planner

type Planner func(events []Event, user interface{}) (interface{}, error)

TODO: This probably should be returning an int indicating partial event processing

(or something like errPartial(nEvents))

returns func(ctx Context, st <T>) (func(*<T>), error), where <T> is the typeOf(User) param

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) Get

func (s *StateGroup) Get(id interface{}) *statestore.StoredState

Get gets state for a single 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

func (*StateGroup) Stop

func (s *StateGroup) Stop(ctx context.Context) error

Stop stops all state machines in this group

type StateHandler

type StateHandler interface {
	// returns
	Plan(events []Event, user interface{}) (interface{}, error)
}

type StateMachine

type StateMachine struct {
	// contains filtered or unexported fields
}

type TestEvent

type TestEvent struct {
	A   string
	Val uint64
}

func (*TestEvent) MarshalCBOR

func (t *TestEvent) MarshalCBOR(w io.Writer) error

func (*TestEvent) UnmarshalCBOR

func (t *TestEvent) UnmarshalCBOR(r io.Reader) error

type TestState

type TestState struct {
	A uint64
	B uint64
}

func (*TestState) MarshalCBOR

func (t *TestState) MarshalCBOR(w io.Writer) error

func (*TestState) UnmarshalCBOR

func (t *TestState) UnmarshalCBOR(r io.Reader) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL