Skip to content

Concepts

A quick map between statechart vocabulary and the fate API. For the why behind it, read Background & the problem and How it works.

Statechart concept → fate

Statechart conceptfate
Atomic / compound / parallel / final stateNodeAtomic / NodeCompound / NodeParallel / NodeFinal
History (shallow / deep)NodeHistory with HistoryShallow / HistoryDeep
Guarded transitionTransitionConfig.Guard (+ And / Or / Not / StateIn combinators)
Entry/exit & transition actionsAssign, Raise, Log, EnqueueActions
Delayed (after) transitionsStateNodeConfig.After, driven by an adapter via PendingTimers / FireTimer
Invoked work / spawned child machinesStateNodeConfig.Invoke, driven via PendingInvocations / ResolveInvocation
Snapshot persistenceActor.Persist / NewActorFromSnapshot
VisualisationRenderASCII, RenderMermaid, RenderGraphJSON

The vocabulary

Machine — the immutable, validated definition. Build once, share everywhere.

Actor — one running instance of a machine. Holds context + active configuration.

Active configuration — the set of states active together (hierarchy + parallelism mean it's a tree, not a single value). Rendered by StateValue.Path().

Context — your typed data carried alongside the state, mutated by Assign actions. A Go type of your choosing, via generics.

Event — your typed trigger. Also your own Go type.

Guard — a pure predicate gating a transition. Composable with And/Or/Not and StateIn. No side effects, no clock.

Action — what runs on entry, exit, or a transition: Assign (update context), Raise (enqueue an internal event), Log, EnqueueActions.

Effect — an intent the engine records as data: a pending timer (After) or a pending invocation (Invoke). An adapter performs it and reports the outcome back.

Building blocks at a glance

  • CreateMachine(MachineConfig[Ctx, Evt]) (*Machine, error) — validate & construct.
  • NewActor(m) / NewActorFromSnapshot[Ctx, Evt](m, blob) — instantiate.
  • Actor.Start(ctx) / Actor.Send(ctx, evt) — run the initial entry / dispatch.
  • Actor.Snapshot() / Actor.Subscribe(...) — read / observe.
  • Actor.Persist() — serialise to JSON.
  • RenderASCII / RenderMermaid / RenderGraphJSON — visualise m.Describe().

Next

  • Examples — each concept as runnable code.
  • Per-symbol reference on pkg.go.dev.
  • The studio to see configurations light up as events fire.

Released under the MIT License · v0.4.0 · pkg.go.dev