statemachine

package
v0.0.0-...-d0c3903 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2023 License: BSD-3-Clause Imports: 1 Imported by: 0

Documentation

Overview

Copyright (C) 2022, Ava Labs, Inc. All rights reserved. See the file LICENSE for licensing terms.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type StateDirection

type StateDirection int64
const (
	Forward StateDirection = iota
	Backward
	Stop
)

type StateMachine

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

keeps track of a linear state sequence given by the non empty slice [states], which can be updated with steps forward and backward by using NextState() with suitable direction. starts in the first elem of [states] and ends either when Stop() is called, or when state passes the last elem of [states]

usage example:

machine, err := NewStateMachine(states)
[ err processing ]
while machine.Running() {
  [do stuff based on machine.CurrentState(), and set direction]
  machine.NextState(direction)
}

func NewStateMachine

func NewStateMachine(states []string) (*StateMachine, error)

func (*StateMachine) CurrentState

func (sm *StateMachine) CurrentState() string

func (*StateMachine) NextState

func (sm *StateMachine) NextState(direction StateDirection)

func (*StateMachine) Running

func (sm *StateMachine) Running() bool

func (*StateMachine) Stop

func (sm *StateMachine) Stop()

Jump to

Keyboard shortcuts

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