class

FSM::StateDefinition(T)

Inherits Reference < Object

A state in the machine definition. Renamed from the old State now that State names the runtime snapshot.

StateDefinition(T) is generic over the caller's context type T, which guards and callbacks receive directly. It is a class with reference semantics: the builder creates it, mutates it during build, and the machine shares one sealed object across every interpreter and fiber. Once sealed, its builder methods raise SealedStateError, which is what keeps a shared definition immutable after build.

Instance methods

all_target_states

The distinct target states reachable from this state, used by the builder to validate that every target names an existing state.

Source
on_blocked(event : String, &block : String, T, Array(String) -> ) : self

Register a handler fired when the event has candidate transitions but every guard rejected. It is keyed per event and does not fire for an unknown event or when any transition succeeds. The handler receives the blocked target ids so it can give a specific reason without re-evaluating any guard. Registering a second handler for the same event replaces the first (last write wins, the same semantics as on_entry and on_exit).

Source
on_entry

Register a callback fired when this state is entered.

Source
on_event(event : String, target : String) : self

Register a transition from this state to a target on an event. Calling on_event repeatedly for one event appends, building the ordered candidate list resolution walks.

Source
on_event(event : String, target : String, &) : self

Register a transition and yield it so a guard, transition callback, or the internal flag can be attached. Because Transition(T) is a class, the yielded object is the same one the machine keeps and the interpreter reads at runtime.

Source
on_exit

Register a callback fired when this state is exited.

Source
on_unknown_event

Register the state-wide handler fired when an event has no transition registered on this state at all. It is not keyed by event because a single handler catches every unregistered event. It does not fire for a blocked event or when any transition succeeds. The handler receives the event and the context, matching on_entry and on_exit; there are no blocked target ids because no transition was registered. Registering a second handler replaces the first (last write wins).

Source