final

fun final(name: String, block: StateBuilder.() -> Unit = {})(source)

Declare a final (terminal) state named name. Entering a final state runs the optional block's onEntry actions, then auto-stops the statechart and fires onCompletion. Final states are leaves with no other triggers (no onMessage, onTimeout, onCondition, onSignal, or substates) — entering one ends the chart's life.

A statechart may declare multiple final states (e.g., success and aborted); the onCompletion handler receives the name of whichever was reached.