fsm

package
v0.0.0-...-ba9c582 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2020 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UnknownStateStr = "unknownState"
	UnknownEventStr = "unknownEvent"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AsyncError

type AsyncError struct {
	Err error
}

AsyncError is returned by FSM.Event() when a callback have initiated an asynchronous state transition.

func (AsyncError) Error

func (e AsyncError) Error() string

type CallbackTypeOutOfRangeError

type CallbackTypeOutOfRangeError struct {
	Type int
}

func (CallbackTypeOutOfRangeError) Error

type CanceledError

type CanceledError struct {
	Err error
}

CanceledError is returned by FSM.Event() when a callback have canceled a transition.

func (CanceledError) Error

func (e CanceledError) Error() string

type Ctx

type Ctx interface {
	Event(id int, args ...interface{}) error
	Transition() error
	Current() (int, string)
	Previous() (int, string)
	Next() (int, string)
	Is(int) bool
	SetState(int) error
	Can(int) bool
	Cannot(int) bool
	AvailableTransitions() []string
}

func NewCtx

func NewCtx(initState StateID, transDescs []TransDesc) (Ctx, error)

NewCtx constructs a FSM context from maps of events, states, and handlers,

type DuplicateCallbackAfterEventError

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

func (DuplicateCallbackAfterEventError) Error

type DuplicateCallbackBeforeEventError

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

func (DuplicateCallbackBeforeEventError) Error

type DuplicateCallbackEnterStateError

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

func (DuplicateCallbackEnterStateError) Error

type DuplicateCallbackError

type DuplicateCallbackError struct {
}

func (DuplicateCallbackError) Error

func (e DuplicateCallbackError) Error() string

type DuplicateCallbackLeaveStateError

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

func (DuplicateCallbackLeaveStateError) Error

type DuplicateTransitionError

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

func (DuplicateTransitionError) Error

func (e DuplicateTransitionError) Error() string

type Event

type Event struct {

	// EventID is id of this event.
	EventID

	// State is the state before the transition.
	Current StateID

	// Next is the state after the transition.
	Next StateID

	// Err is an optional error that can be used for capturing
	// any error inside event handler
	Err error

	// Args is a optinal list of arguments passed to the event handler.
	Args []interface{}
}

Event is the info that gets passed as a reference to the Handler.

type EventID

type EventID int

type EventMap

type EventMap map[EventID]string

type EventOutOfRangeError

type EventOutOfRangeError struct {
	ID EventID
}

func (EventOutOfRangeError) Error

func (e EventOutOfRangeError) Error() string

type EventStartReserveError

type EventStartReserveError struct {
}

func (EventStartReserveError) Error

func (e EventStartReserveError) Error() string

type EventStartReserveMissingError

type EventStartReserveMissingError struct {
}

func (EventStartReserveMissingError) Error

type Handler

type Handler interface {
	Handle(event *Event)
}

Handler is an interface that expects event Handle function. Event is the current event that is to be handled.

type InTransitionError

type InTransitionError struct {
	Event string
}

InTransitionError is returned by FSM.Event() when an asynchronous transition is already in progress.

func (InTransitionError) Error

func (e InTransitionError) Error() string

type InternalError

type InternalError struct{}

InternalError is returned by FSM.Event() and should never occur. It is a probably because of a bug.

func (InternalError) Error

func (e InternalError) Error() string

type InvalidEventError

type InvalidEventError struct {
	Event string
	State string
}

InvalidEventError is returned by FSM.Event() when the event cannot be called in the current state.

func (InvalidEventError) Error

func (e InvalidEventError) Error() string

type NoTransitionError

type NoTransitionError struct {
	Err error
}

NoTransitionError is returned by FSM.Event() when no transition have happened, for example if the source and destination states are the same.

func (NoTransitionError) Error

func (e NoTransitionError) Error() string

type NotInTransitionError

type NotInTransitionError struct{}

NotInTransitionError is returned by FSM.Transition() when an asynchronous transition is not in progress.

func (NotInTransitionError) Error

func (e NotInTransitionError) Error() string

type StateID

type StateID int

type StateMap

type StateMap map[StateID]string

type StateOutOfRangeError

type StateOutOfRangeError struct {
	ID StateID
}

func (StateOutOfRangeError) Error

func (e StateOutOfRangeError) Error() string

type StateStartReserveError

type StateStartReserveError struct {
}

func (StateStartReserveError) Error

func (e StateStartReserveError) Error() string

type StateStartReserveMissingError

type StateStartReserveMissingError struct {
}

func (StateStartReserveMissingError) Error

type TransDesc

type TransDesc struct {
	// EventID is the id of the current event triggering this transition
	Event EventID

	//  A slice of current states that the FSM must be in to perform a
	// state transition.
	CurrentStates []StateID

	// NextState state that the FSM has to jump upon successful transition
	NextState StateID

	//Event Handler
	Handler
}

TransDesc describes a event transition

The event can have one or more current states that are valid for performing the transition. If the FSM is in one of the current states it will end up in the specified next state, invoking defined event handlers.

type UnknownEventError

type UnknownEventError struct {
	Event string
}

UnknownEventError is returned by FSM.Event() when the event is not defined.

func (UnknownEventError) Error

func (e UnknownEventError) Error() string

Jump to

Keyboard shortcuts

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