finitestate

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: May 28, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusNew       = fsm.StatusNew
	StatusBooting   = fsm.StatusBooting
	StatusRunning   = fsm.StatusRunning
	StatusReloading = fsm.StatusReloading
	StatusStopping  = fsm.StatusStopping
	StatusStopped   = fsm.StatusStopped
	StatusError     = fsm.StatusError
	StatusUnknown   = fsm.StatusUnknown
)

Variables

View Source
var TypicalTransitions = fsm.TypicalTransitions

TypicalTransitions is a set of standard transitions for a finite state machine.

Functions

func New

func New(handler slog.Handler) (*fsm.Machine, error)

New creates a new finite state machine with the specified logger using "standard" state transitions.

Types

type Machine

type Machine interface {
	// Transition attempts to transition the state machine to the specified state.
	Transition(state string) error

	// TransitionBool attempts to transition the state machine to the specified state.
	TransitionBool(state string) bool

	// TransitionIfCurrentState attempts to transition the state machine to the specified state
	TransitionIfCurrentState(currentState, newState string) error

	// SetState sets the state of the state machine to the specified state.
	SetState(state string) error

	// GetState returns the current state of the state machine.
	GetState() string

	// GetStateChan returns a channel that emits the state machine's state whenever it changes.
	// The channel is closed when the provided context is canceled.
	GetStateChan(ctx context.Context) <-chan string

	// GetStateChanBuffer returns a channel with a configurable buffer size that emits the state machine's state whenever it changes.
	// The channel is closed when the provided context is canceled.
	GetStateChanBuffer(ctx context.Context, bufferSize int) <-chan string
}

Machine defines the interface for the finite state machine that tracks the HTTP server's lifecycle states. This abstraction allows for different FSM implementations and simplifies testing.

Jump to

Keyboard shortcuts

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