This library is in flux. APIs may change without notice. Generated from source with koruc 0.1.7 on 11/4/2026.
Channel
import std/channelKoru Standard Library: Channels — bounded MPMC channels over proto elements.
channel.kz · 6 tors
Koru Standard Library: Channels — bounded MPMC channels over proto elements. · 63 more lines
// CHANNEL.NEW — `std/channel:new(<name>, capacity: N) { kind: Proto, ... }`:
// declare the channel, then collect every `consume` join in the program and
// splice its `!` arms into the generated drain.
~[keyword|comptime|transform] pub tor new {
expr: Expression,
source: ?Source,
invocation: *const Invocation,
item: std/compiler:*const Item,
program: std/compiler:*const Program,
reporter: std/compiler:*ErrorReporter,
allocator: std.mem.Allocator
} -> SiteResult// CHANNEL.DEFAULT — the bare-reference join `std/channel(<name>) ! arms`.
// A [pre]-phase rewrite to the internal `consume` verb — the store
// `default`→`watch` pattern — so `new` collects every join program-wide
// before the main phase runs.
~[keyword|comptime|transform|pre] 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// CHANNEL.CONSUME — the join site's own transform (internal verb; also the
// literal spelling). By the time this fires on a well-formed program, `new`
// has already collected the arms — the site self-erases. Firing with the
// decl still untransformed means the join precedes it (rung-one ordering);
// no decl anywhere is a plain unknown-channel diagnostic.
~[keyword|comptime|transform] pub tor consume {
expr: Expression,
invocation: *const Invocation,
item: std/compiler:*const Item,
program: std/compiler:*const Program,
reporter: std/compiler:*ErrorReporter,
allocator: std.mem.Allocator
} -> SiteResult~[keyword|comptime|transform] pub tor send {
expr: Expression,
invocation: *const Invocation,
item: std/compiler:*const Item,
program: std/compiler:*const Program,
reporter: std/compiler:*ErrorReporter,
allocator: std.mem.Allocator
} -> SiteResult~[keyword|comptime|transform] pub tor recv {
expr: Expression,
invocation: *const Invocation,
item: std/compiler:*const Item,
program: std/compiler:*const Program,
reporter: std/compiler:*ErrorReporter,
allocator: std.mem.Allocator
} -> SiteResult~[keyword|comptime|transform] pub tor close {
expr: Expression,
invocation: *const Invocation,
item: std/compiler:*const Item,
program: std/compiler:*const Program,
reporter: std/compiler:*ErrorReporter,
allocator: std.mem.Allocator
} -> SiteResult~part custody koru_std/channel.custody.kz
Koru Standard Library: the `custody` part of channel — obligation transit. Joined via `~part custody` in channel.kz; merged into the channel module. Custody detection — the per-edge obligation contract (concepts/frag-custody-transit-is-an-edge-contract). A send of a value whose producer ISSUED it (`-> T<state!>` — the `!` suffix marks an issued obligation; `T<!state>` consumes, `T<state>` borrows) transits custody through the vessel. Resolution this rung is same-flow: the ident's `return_binding` producer. Anything unresolvable stays plain. The machinery is transform composition: `new` scans send sites (this part) and emits the `take`/`obligate` pair plus consumer units (the transit part); `send` injects the take under `| ok` alone; consumer units mint via obligate before the arm body.
~part transit koru_std/channel.transit.kz
Koru Standard Library: the `transit` part of channel — emission of the custody pair and the consumer units. Joined via `~part transit` in channel.kz; merged into the channel module. Detection lives in the custody part (which sends transit, under what state); this half emits the machinery that carries it: `take`/`obligate` per custodial kind, the `!`-arm units that mint via obligate, and the take node injected under a custodial send's `| ok`.
~part home koru_std/channel.home.kz
Channel home resolution — where a channel declaration or a chain-step flow lives, spelled for synthesized path qualifiers. Joined via `~part home` in channel.kz; merged into the channel module. The generic tree walks (moduleHome, containingFlow, findEventDecl) live in ast_functional — every comptime module needs them and .kz parts cannot share private fns. This file also declares the module's ast_functional import for that reason; channel.kz's `std`/`ast` are already module-wide.
~part leaves koru_std/channel.leaves.kz
Koru Standard Library: the `leaves` part of channel — proto leaf reading. Joined via `~part leaves` in channel.kz; merged into the channel module. A channel kind is a proto name; this part is everything the transform needs to read that name's LEAVES: the field list (`FieldPair`, `protoSourceText`/`protoFields`/`expandInto`), the Zig material each leaf lowers to (`zigFieldType`), and the owned-leaf split — `*mod:Type<state!>` spells a debt at a path, so composite kinds get a `take` param / arg per leaf (`takeFields`, `takeArgs`).
~part units koru_std/channel.units.kz
Koru Standard Library: the `units` part of channel — consumer-unit emission. Joined via `~part units` in channel.kz; merged into the channel module. Each `!`-arm of a consumer compiles to a callable void unit — an event_decl + impl pair on pump.kz's drained-unit convention. A custodial kind's unit takes a plain `__payload` and obligates it onto the arm's own binding as the first step, so `! <kind> v |> body` runs with `v` live — whole-value `<state!>` or per-leaf proto debts alike.