state_machine

package
v0.0.0-...-1ea9000 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: BSD-3-Clause Imports: 6 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

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

Builder is a helper struct used for constructing StateMachines.

func NewBuilder

func NewBuilder() *Builder

NewBuilder returns a Builder instance.

func (*Builder) Build

func (b *Builder) Build(ctx context.Context, gcsClient gcs.GCSClient, gsPath string) (*StateMachine, error)

Build and return a StateMachine instance.

func (*Builder) F

func (b *Builder) F(name string, fn TransitionFn)

Add a transition function with the given name. Allows nil functions for no-op transitions.

func (*Builder) SetInitial

func (b *Builder) SetInitial(s string)

Set the initial state.

func (*Builder) T

func (b *Builder) T(from, to, fn string)

Add a transition between the two states with the given named function.

type StateMachine

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

StateMachine is a simple state machine implementation which persists its current state to a file.

func (*StateMachine) Current

func (sm *StateMachine) Current() string

Return the current state.

func (*StateMachine) GetTransitionName

func (sm *StateMachine) GetTransitionName(dest string) (string, error)

Return the name of the transition function from the current state to the given state.

func (*StateMachine) ListStates

func (sm *StateMachine) ListStates() []string

ListStates returns the list of all states in the StateMachine.

func (*StateMachine) Transition

func (sm *StateMachine) Transition(ctx context.Context, dest string) error

Attempt to transition to the given state, using the transition function.

type TransitionFn

type TransitionFn func(ctx context.Context) error

TransitionFn is a function to run when attempting to transition from one State to another. It is okay to give nil as a noop TransitionFn.

Jump to

Keyboard shortcuts

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