class FSM::Machine(T)

Overview

The immutable, sealed machine definition.

A machine is built once by a machine-scoped builder, then shared across any number of interpreters and fibers. It resolves transitions and answers state lookups; it never executes user callbacks. Construction goes only through .build; the old array-of-states Machine.create form is gone.

T is the caller's context type. T = Nil is unsupported: a contextless caller uses FSM::Context. .build rejects Machine(Nil) at compile time with a diagnostic naming FSM::Context.

Defined in:

fsm/machine.cr

Class Method Summary

Instance Method Summary

Class Method Detail

def self.build(id : String, &) : Machine(T) #

Build a machine with a machine-scoped builder. The yielded builder registers states; at the end of the block it validates every transition target and seals every definition, then returns the immutable machine.


[View source]

Instance Method Detail

def id : String #

[View source]
def states : Hash(String, StateDefinition(T)) #

A shallow copy of the states, so callers cannot add, delete, or replace entries in the machine's internal definition. The StateDefinition values are shared but sealed, so the definition stays immutable. Internal code reads @states directly.


[View source]