fsm

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2025 License: BSD-2-Clause Imports: 1 Imported by: 0

Documentation

Overview

Package fsm provides a simple but powerful finite state machine implementation.

The design is inspired by Rob Pike's talk "Lexical Scanning in Go".

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run[T any](ctx context.Context, args T, start State[T]) (T, error)

Run executed the finite state machine with args of any type and start as the first state. It keeps executing the states until the current state is nil. In case a state returns an error, the execution stops and the error is returned.

Types

type State

type State[T any] func(ctx context.Context, args T) (T, State[T], error)

State represents a state in the finite state machine. It takes args as a set of arguments and returns the arguments for the next state, the next State to run or an error.

Returning a nil State indicates the successful end of the state machine.

Jump to

Keyboard shortcuts

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