fsm

package module
v0.0.0-...-f4a273f Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2015 License: LGPL-2.1 Imports: 2 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

fsm

A simple but powerful golang FSM library.

Originally developed for use in the Gossip SIP stack (see here for an example), but can be used for anything.

For full package documentation, see the GoDoc page.

Documentation

Overview

General Purpose FSM library.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action func() Input

An Action describes something an FSM will do. It returns an Input to allow for automatic chaining of actions.

type ClashingStateError

type ClashingStateError int

ClashingStateError indicates that an attempt to define an FSM where two states share the same index was made.

func (ClashingStateError) Error

func (err ClashingStateError) Error() string

type FSM

type FSM struct {
	sync.Mutex
	// contains filtered or unexported fields
}

FSM is the main structure defining a Finite State Machine.

func Define

func Define(states ...State) (*FSM, error)

Define an FSM from a list of States. Will return an error if you try to use two states with the same index.

func (*FSM) Spin

func (f *FSM) Spin(in Input) error

Spin the FSM one time. This method is thread-safe.

type ImpossibleStateError

type ImpossibleStateError int

ImpossibleStateError indicates that an FSM is in a state which wasn't part of its definition. This indicates that either the definition is wrong, or someone is monkeying around with the FSM state manually.

func (ImpossibleStateError) Error

func (err ImpossibleStateError) Error() string

type Input

type Input int

An Input to give to an FSM.

const (
	NO_INPUT Input = -1
)

func NO_ACTION

func NO_ACTION() Input

NO_ACTION is useful for when you need a certain input to just change the state of the FSM without doing anytyhing else.

type InvalidInputError

type InvalidInputError struct {
	StateIndex int
	Input      Input
}

InvalidInputError indicates that an input was passed to an FSM which is not valid for its current state.

func (InvalidInputError) Error

func (err InvalidInputError) Error() string

type Outcome

type Outcome struct {
	State  int
	Action Action
}

An Outcome describes the result of running an FSM. It describes which state to move to next, and an Action to perform.

type State

type State struct {
	Index    int
	Outcomes map[Input]Outcome
}

A State describes one possible state of an FSM. It maps Inputs to Outcomes.

Jump to

Keyboard shortcuts

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