statemachine

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

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

Go to latest
Published: May 3, 2013 License: MIT Imports: 0 Imported by: 0

README

go-statemachine

About

This package provides an implementation of a finite state machine in Go (http://golang.org/), inspired by David Mertz's article "Charming Python: Using state machines" (http://www.ibm.com/developerworks/library/l-python-state/index.html).

Usage

Install the package in your environment:

$ go get github.com/dpapathanasiou/go-statemachine

Make sure the GOPATH environment variable is defined correctly and test it:

$ go test github.com/dpapathanasiou/go-statemachine
ok  	github.com/dpapathanasiou/go-statemachine	0.014s

To use it within your own code, import "github.com/dpapathanasiou/go-statemachine" and instantiate the state machine with an empty map of handler functions, along with the string name of the initial state handler function.

Example

See the statemachine_test.go file included in this package.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler func(interface{}) (string, interface{})

type Machine

type Machine struct {
	Handlers   map[string]Handler
	StartState string
	EndStates  map[string]bool
}

func (*Machine) AddEndState

func (machine *Machine) AddEndState(endState string)

func (*Machine) AddState

func (machine *Machine) AddState(handlerName string, handlerFn Handler)

func (*Machine) Execute

func (machine *Machine) Execute(cargo interface{})

Jump to

Keyboard shortcuts

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