Machines examples¶
Worked, runnable apps — the machine features you read about, running.
New to machines? Build one yourself first — the Tutorial walks you through a login machine step by step — then skim Concepts for the whole model. After that, work through the apps below in order: each adds a little more machinery than the last.
- state_machine_walkthrough — your first machine, end to end. The Concepts login flow as runnable code: a self-contained transition table, with guards and actions living with the spec rather than in a global registry, driven headlessly to show the pure-transition + drain testing story. Read first: Concepts. → source
- nine_states — parallel regions and tags. One
:type :parallelmachine with three orthogonal regions (:data/:form/:mode) and:tags; a render-priority table over the tag union collapses all nine canonical UI states into a singlecasein the root view. Read first: Parallel states and Tags. → source - long_running_work — spawning workers, and cancelling them cleanly. Cancellable long-running work via
:spawn-all: one parent coordinator spawns N parallel worker children, with per-step progress as an internal self-transition and a cooperative cancellation cascade that fires on every exit path — including unmount. Read first: Actors. → source - websocket — the lot, in one machine. The canonical connection machine: a hierarchical compound
:activestate parenting connect/auth/connected, a:spawn'd socket actor bound to that state,:afterexponential backoff,:alwaysqueue-flush on reconnect, and connection-epoch staleness against the live socket id. Read first: Hierarchical states, Actors, and Automatic transitions. → source
One more — not a machine, included only for substrate variety:
- process_monitor_helix — a Helix two-pane process monitor. It shows Helix consuming subs via
use-subscribeand a live:dispatch-latertick loop, but has no state machine. Reach for it to see the ideas under another substrate, not as a machine example. → source