Skip to main content
Everything here lowers to the five reads, the six writes and submit (once, then, due, within). A wait is a committed task, never a sleeping handler.

Wait for an instant

Submit a mutation with due. It runs in its own transaction once the instant passes:
A clock that fires on its own is a reaction: mutation({ on: every({ minutes: 5 }), roles: [closer] }, …) or on: cron("0 18 * * 1-5", "Europe/Paris"). Its handler receives { at }. A machine edge with due moves a fact at the instant its field holds, without any task (see Tables).

One live task per fact: turns

@bijectionhq/library-work gives a fact one live task, named by a generation field. turn.arm(ctx, table, key, to, args, { then, due, within, field }) bumps the generation and submits the new task in one commit. turn.current(ctx, table, key) answers whether this delivery is the live one, so a superseded or stopped turn does nothing. turn.stop bumps the generation without submitting.
Declare the field t.number starting at 0, or t.maybe(t.number). The live task’s once is turnOnce(key, field, generation).

Controllers

controller({ table, label, due, advance }) acts on a fact only on its current turn and only when due. It returns a subtree holding its own tick continuation; place it in the tree and start it from any mutation.
After acting it re-arms at the next observed instant (at least one second later), or stops when the fact is inactive. A reconciler is a controller that runs one bounded page of corrections per turn.

Leases

lease({ n, label }) keeps at most n live, epoch-fenced tenures per name. acquire answers a tenure or null. guard answers a tenure only while it outlives the transaction’s commit bound (frame.now + frame.within), and its fact joins the read set, so a concurrent acquire, renew or end conflicts with it. submit fences a task: its deadline must end inside the tenure, and end is clamped to the latest covered deadline.

Pools

pool({ label, n, to, within, settled }) admits at most n items to a target at once and queues the rest. Each admitted item is one task with once: ["pool", name, key, epoch]. The pool owns its settle continuation and its wake turn; settled(ctx, item, result) is your reaction.

Unique reservations

registry({ label }) reserves keys across tables. reserve answers a Reservation or null when taken, unreserve frees exactly that reservation, and taken is a presence read (ctx.has) at the registry’s label.

Retry timing

retryPolicy is a value type, { maxAttempts, initialBackoff, base, maxBackoff, jitter }, with durations as Temporal.Duration. retryPolicyDelay(policy, attempts, random) answers the next delay, or null when attempts are spent. Submit the retry with that delay as due.