This library is in flux. APIs may change without notice. Generated from source with koruc 0.1.7 on 11/4/2026.

Pump

import std/pump

Koru Standard Library: Pump — compile-time composition of participants.

pump.kz · 4 tors

Koru Standard Library: Pump — compile-time composition of participants. · 37 more lines
Koru Standard Library: Pump — compile-time composition of participants. std/pump:create(main) | drained |> std/io:print.ln("all participants retired") std/pump(main) ! step |> tick-step() ! live |> tick-live() ! wait i |> tick-wait(i: i) std/pump:run(main) ! idle |> std/time:sleep-ms(ms: 2) A PARTICIPANT is anything that can answer up to three verbs: step() -> i32 advance every live instance once; return how many made progress this pass. Required. live() -> i64 how many instances are live; 0 = retired. Absent = the participant is immortal — it never drains the pump. wait(i) -> interest instance i's blocking interest — the RETURN TYPE is the vocabulary: `-> i32` fd, `-> i128` re-poll ns, `{ fd, wait_ns }` both; presence, never sentinels. Optional; unarmed participants add nothing to the wait. The join site `std/pump(name)` carries the verbs as `!` arms — the same reference form `std/store(name) ! field` uses for standing watches. Pass order is join order (document order). Each arm's body is compiled into a generated unit `__pump_<name>_{step,live,wait}_<idx>` — the verbs are ordinary calls, so a participant is any author-written unit: a module's singleton state, a hand-managed array, or a `! step` store (which exposes exactly these verbs as `<store>-step` / `<store>-live` / `<store>-wait`). The pump knows none of that — it calls names. `run` drives passes until Σ live() is 0 — a pump of only immortals IS the program's event loop. On an all-idle pass `run` fires `! idle` in the loop; unarmed it composes the wait itself — one `poll()` over every joined `wait` interest capped by the nearest `wait_ns`, else 1ms.

create

keywordcomptimetransformaspirational open-pump-marker-wire koru_std/pump.kz:412

default

keywordcomptimetransform koru_std/pump.kz:526

~part explain koru_std/pump.explain.kz

Koru Standard Library: the `explain` part of pump — joined via `~part explain` in pump.kz; members land in koru_pump. The pump is the most distributed surface in the stdlib: participants join from anywhere via `std/pump(name) ! step |> ...` and `run` enumerates them by generated-decl name. Nothing in any single file answers "who joined, which verbs each answers, does this pump ever drain" — the explainer folds the source sites in document order with the SAME checks the create/join/run transforms apply; a program that refuses still explains itself, each refusal verbatim via the shared `PM` messages. Callee spellings come from PH.lastInvocation — the same read the join transform uses — and `PS.synthesized` names callees the store transform will generate.

explain-pump

comptimeexplainer koru_std/pump.explain.kz:210

~part messages koru_std/pump.messages.kz

Koru Standard Library: the `messages` part of pump — joined via `~part messages` in pump.kz; members land in koru_pump. Every refusal text the three pump transforms can raise, named once. The transforms pass these to `ast.refusal` (they carry the KORU161 format args); the explainer formats the SAME consts for its `status` rows — so what `koruc explain` reports for a refusing program is the diagnostic verbatim, and the two can never drift on wording.

~part run-msgs koru_std/pump.run-msgs.kz

Koru Standard Library: the `run-msgs` part of pump — joined via `~part run-msgs` in pump.kz; members land in koru_pump. The `run` transform's refusal texts — split off `pump.messages.kz` when the retire contract outgrew that file's pin. Same rule applies: the explainer formats these verbatim, so wording lives here once.

~part synth koru_std/pump.synth.kz

Koru Standard Library: the `synth` part of pump — joined via `~part synth` in pump.kz; members land in koru_pump. A join arm's callee isn't always a declared tor: a store's `! step` / `! wait` arms SYNTHESIZE `<s>-step` / `<s>-live` / `<s>-wait` units at transform time, so nothing named `tasks-step` exists in the pre-transform tree the explainer folds. `synthesized` recognizes `<store>-<verb>` against a `std/store:new` site carrying the arm that generates it — reported as generated (with the generator site as `gen` witness), never refused.

~part wit koru_std/pump.wit.kz

Koru Standard Library: the `wit` part of pump — joined via `~part wit` in pump.kz; members land in koru_pump. Witness emission for join verb rows: each row's `at` carries the arm's call-site hash, plus the `std/store:new` generator site when the callee is synthesized — so a pump row resolves back through the door that minted it.

~part wait koru_std/pump.wait.kz

Koru Standard Library: the `wait` part of pump — joined via `~part wait` in pump.kz; members land in koru_pump. The `! wait` interest contract. A participant's wait callee declares its blocking interest BY RETURN TYPE: `-> i32` is a descriptor to poll, `-> i128` a relative re-poll duration in ns, `-> { fd: i32, wait_ns: i128 }` both at once. Field PRESENCE is the vocabulary — a participant never writes sentinels. The generated wait units normalize to `{ fd, wait_ns }` with internal sentinels (-1 / maxInt) for whichever interest the callee didn't declare, so the union poll loop reads one shape.

~part run koru_std/pump.run.kz

Koru Standard Library: the `run` part of pump — joined via `~part run` in pump.kz; members land in koru_pump. PUMP.RUN — drive a declared pump until every participant drains. std/pump:run(main) ! idle |> ... Enumerates the joined `__pump_<name>_step_<i>` units and emits `__pump_run_<name>`: while any participant's `live` counts rows, step each in join order. A pass with zero progress fires `! idle` — armed, the arm runs in the loop; unarmed, the union wait collects every `wait` unit's interests and polls once, or breathes 1ms when nothing was declared. Retirement: a participant may emit `__pump_<name>_retired_<i>` — fired by the driver exactly once, on the first pass whose `live` answers 0, ahead of `| drained`. This is where a captured participant's run-terminal arms (`| stopped`, `| done`) land. It requires `live` — an immortal participant never retires.

run

keywordcomptimetransform koru_std/pump.run.kz:22