fsmtool

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2020 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package fsmtool contains tools for creating FSMs, particularly transitioning between states. State machines in Go is quite simple so there's no need for a library that handles *everything*.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type StateTransitionTable

type StateTransitionTable struct {
	CurrentState     interface{}
	LogOnError       bool
	PanicOnError     bool
	LogStates        bool
	LogTransitions   bool
	Name             string
	AllowInvalid     bool // Allow invalid state transitions (but log errors)
	ValidTransitions map[interface{}][]interface{}
}

StateTransitionTable is a tool to manage state transitions.

func NewStateTransitionTable

func NewStateTransitionTable(initialState interface{}) *StateTransitionTable

NewStateTransitionTable creates a new state transition table.

func (*StateTransitionTable) AddTransitions

func (s *StateTransitionTable) AddTransitions(states ...interface{}) bool

AddTransitions adds a state transition to the table

func (*StateTransitionTable) Apply

func (s *StateTransitionTable) Apply(newState interface{}, code func(stt *StateTransitionTable)) bool

Apply applies the state transition with the given function and logs debug information

func (*StateTransitionTable) DumpTransitions

func (s *StateTransitionTable) DumpTransitions(writer io.Writer)

DumpTransitions dumps the transitions in a dot-compatible format

func (*StateTransitionTable) SetState

func (s *StateTransitionTable) SetState(state interface{}) bool

SetState sets a new state if it is valid

Jump to

Keyboard shortcuts

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