statemachine

package
v1.5.3-rc.0 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: BSD-3-Clause Imports: 1 Imported by: 1

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