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()
Click to show internal directories.
Click to hide internal directories.