fsm

package module
v0.0.0-...-357ae87 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2020 License: MIT Imports: 9 Imported by: 0

README

go-fsm GoReportCard GoDoc

A golang library that can be used to construct finite-state machines.

A finite-state machine is an abstract machine that can be in exactly one of a finite number of states at any given time.

The API and design of this library is inspired by the finite-state machine implementation in the golang template lexer.

Installation

To install go-fsm, use go get.

go get github.com/austingebauer/go-fsm

Then import the library into your Go program.

import "github.com/austingebauer/go-fsm"

Usage

See example usage in example/main.go, which uses go-fsm to write a finite-state machine for the pacman ghosts state machine.

To run the example:

go run example/main.go
Generating a State Diagram

To generate a state diagram showing the states, transitions, and steps of the finite-state machine execution:

dot example/dot_graph.gv -T png > example/dot_graph.png && open example/dot_graph.png

An example image generated from running the example finite-state machine:

go-fsm finite-state-machine

Contributing

Pull requests are welcome.

For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests along with changes.

License

MIT

Documentation

Overview

Package fsm is a library that can be used to construct finite-state machines.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMachine

func NewMachine() *finiteStateMachine

NewMachine initializes and returns a new finite-state machine.

Types

type State

type State func() (State, error)

State is a function that handles a machine state and returns the next machine state.

A function that participates as a state in the finite-state machine must be of the State type.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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