This library is in flux. APIs may change without notice. Generated from source with koruc 0.1.7 on 10/5/2026.
Pump
~import std/pumpKoru Standard Library: Pump — compile-time composition of participants.
pump.kz · 2 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.
~[
- keyword
- comptime
- transform
- aspirational open-pump-marker-wire
Comment-wire markers restated per participant transform; the typed
program-item migration is resolved — concepts/frag-comment-markers-are-the-inter-transform-wire.
]pub tor create {
expr: Expression,
invocation: *const Invocation,
item: std/compiler:*const Item,
program: std/compiler:*const Program,
reporter: std/compiler:*ErrorReporter,
allocator: std.mem.Allocator
} -> SiteResult// PUMP.DEFAULT — the bare `std/pump(name)` reference form: a participant JOIN.
//
// std/pump(main)
// ! step |> <call> — required, `-> i32` progress count
// ! live |> <call> — optional, `-> i64` live-instance count
// ! wait i |> <call(i)> — optional, interest by return type:
// `i32` (fd) / `i128` (re-poll ns) / `{ fd, wait_ns }`
//
// Each arm compiles into `__pump_<name>_{step,live,wait}_<idx>`; run
// enumerates them. The verbs are ordinary calls — the pump never learns what
// implements them.
~[keyword|comptime|transform] pub tor default {
expr: Expression,
invocation: *const Invocation,
item: std/compiler:*const Item,
program: std/compiler:*const Program,
reporter: std/compiler:*ErrorReporter,
allocator: std.mem.Allocator
} -> SiteResult