Skip to content

@channels

Import this module with import @channels.

Message passing between threads. Compiler-only feature; requires POSIX threads.

Function Signature Description
open (capacity i64) -> Channel Create a buffered channel
send (ch Channel, value i64) Send an i64 value into a channel
receive (ch Channel) -> i64 Receive an i64 value from a channel (blocks if empty)
close (ch Channel) Close a channel
try_send (ch Channel, value i64) -> bool Non-blocking send; returns false if full
try_receive (ch Channel) -> (i64, bool) Non-blocking receive; returns value and success

A capacity below 1 is a runtime panic (P0173), as is a capacity whose buffer cannot be allocated or exceeds --arena-limit. send on a closed channel is a runtime panic (P0172), including a send that was blocked on a full channel when it closed; try_send returns false instead.

Channels are i64-only. Sending non-i64 types (string, f64, bool, etc.) is a compile-time error.

A Channel that open did not create (a zero-value one) is a runtime panic (P0169) in every function above.