fsm

package
v0.0.0-...-21d6f6e Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2016 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnknownState    error = errors.New("unknown-state")
	ErrStateNotAllowed error = errors.New("state-not-allowed")
	ErrInvalidState    error = errors.New("invalid-state")
)

Functions

This section is empty.

Types

type Fsm

type Fsm struct {
	Definition StateTransitions

	CustomData interface{} `json:"custom_data,omitempty"`
	History    []*FsmState `json:"history"`

	Expiration <-chan *FsmState `json:"-"`
	Complete   <-chan *FsmState `json:"-"`
	// contains filtered or unexported fields
}

func NewFsm

func NewFsm(def StateTransitions, initial State) *Fsm

func (*Fsm) Current

func (this *Fsm) Current() *FsmState

func (*Fsm) Next

func (this *Fsm) Next(next State, message string, observed error) (*FsmState, error)

Transition to the next state specified. Once the state is obtained, the deadline can be set.

type FsmState

type FsmState struct {
	Id      int       `json:"id"`
	State   State     `json:"state"`
	Started time.Time `json:"started"`
	Expiry  time.Time `json:"expiry"`
	Message string    `json:"message"`
	Error   error     `json:"error"`
	// contains filtered or unexported fields
}

func (*FsmState) SetDeadline

func (this *FsmState) SetDeadline(duration time.Duration) error

Sets the start time and the expiry. This also starts a timer

func (*FsmState) String

func (this *FsmState) String() string

type Managed

type Managed interface {
	GetKey() interface{}
}

For something to be managed, it has to have a key or indexable attribute.

type ManagedSet

type ManagedSet interface {
	Managed
	Add(Managed) *Fsm
	Remove(Managed)
	Instances() []*Fsm
	Empty() bool
}

Managed set of objects by some common criteria / key

type MinHeap

type MinHeap struct {
	EqualFunc func(a, b interface{}) bool
	LessFunc  func(a, b interface{}) bool
	NewFunc   func(interface{}) ManagedSet
	// contains filtered or unexported fields
}

Min-heap of container groups prioritized by the version

func (*MinHeap) Add

func (h *MinHeap) Add(c Managed) *Fsm

func (*MinHeap) Instances

func (h *MinHeap) Instances(groupBy interface{}) []*Fsm

func (*MinHeap) Len

func (h *MinHeap) Len() int

func (*MinHeap) Less

func (h *MinHeap) Less(i, j int) bool

func (*MinHeap) Pop

func (h *MinHeap) Pop() interface{}

func (*MinHeap) Push

func (h *MinHeap) Push(x interface{})

func (*MinHeap) Remove

func (h *MinHeap) Remove(c Managed)

func (*MinHeap) Swap

func (h *MinHeap) Swap(i, j int)

func (*MinHeap) Visit

func (h *MinHeap) Visit(visit func(ManagedSet))

type State

type State interface {
	String() string
	Equals(State) bool
}

type StateTransitions

type StateTransitions interface {
	Next(State) ([]State, bool)
}

Jump to

Keyboard shortcuts

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