fsm

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: Apache-2.0 Imports: 0 Imported by: 2

Documentation

Overview

Package fsm is what every merilo machine imports: the outcome Fire returns, the error a holder reports for a refused event, and the bounded counter a machine keeps instead of a raw integer. A machine declares only its own states, events, actions and transitions.

fsm imports nothing, allocates nothing and never panics.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Counter

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

Counter is a count from zero to a limit fixed when it is built. It never passes either end: Inc refuses at the limit and Dec at zero. It is a comparable value, so a machine holding one stays comparable.

func NewCounter

func NewCounter(limit int64) Counter

NewCounter returns a counter at zero that counts up to limit. A negative limit counts nothing.

func (Counter) Dec

func (c Counter) Dec() (next Counter, ok bool)

Dec returns the counter one lower, or the counter unchanged and false at zero.

func (Counter) Full

func (c Counter) Full() bool

Full reports whether the counter is at its limit.

func (Counter) Inc

func (c Counter) Inc() (next Counter, ok bool)

Inc returns the counter one higher, or the counter unchanged and false at its limit.

func (Counter) Limit

func (c Counter) Limit() int64

Limit returns the most the counter can reach.

func (Counter) Value

func (c Counter) Value() int64

Value returns the count.

type Outcome

type Outcome int64

Outcome reports what Fire did with an event.

const (
	Moved    Outcome // the event took effect: the machine changed, or its actions say what to do
	Ignored          // nothing to do; the machine is unchanged
	Rejected         // the event is not allowed now; the machine is unchanged
	Invalid          // an impossible state or event, refused with the machine unchanged
)

Outcome values. The zero value is an unexported sentinel, so an outcome that was never set matches no case.

func (Outcome) Err

func (o Outcome) Err() error

Err is the holder's verdict on an outcome: nil when the event was handled, Moved or Ignored, and a Refusal for anything else.

func (Outcome) String

func (o Outcome) String() string

String names the outcome, or returns "invalid" for a value outside the declared constants.

type Refusal

type Refusal Outcome

Refusal is the error Err returns for an outcome that refused its event. A holder wraps it with the event and state, and tests for it with errors.As.

func (Refusal) Error

func (r Refusal) Error() string

Error says why the event was refused.

Jump to

Keyboard shortcuts

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