Skip to content

std/channel

Import with import std/channel.

type Channel<'T>

Typed FIFO channel for communication between tasks. Producers Channel.send values; consumers Channel.receive them in arrival order. Capacity at construction is the buffer size: capacity: 0 is unbuffered, so every send waits until a paired receive.

Channels live independent of any specific concurrent { } block: a channel can be created in one block, returned out of it, and consumed by a later block. They are garbage-collected by the host runtime when no Nomi reference remains.

fn new(capacity: Int): Channel<'T>

type function on Channel

Construct a fresh Channel<'T> with the given buffer capacity. capacity: 0 yields an unbuffered channel where every send waits for a paired receive. Capacities greater than 0 buffer up to capacity pending values before send blocks.

fn send(ch: Channel<'T>, value: 'T): Result<Unit, ChannelClosed>

type function on Channel

Send a value on the channel. Blocks until the value is taken (for unbuffered channels) or capacity is available (for buffered). Returns Err(ChannelClosed) if the channel was closed at send time. Cancellation-aware: when called from inside a concurrent { } block whose context fires (via deadline or upstream cancellation), the send unwinds silently — user code observes ancestor cancellation through other cancellation-aware sites, not here.

fn receive(ch: Channel<'T>): Maybe<'T>

type function on Channel

Receive the next value from the channel. Blocks until a value arrives, the channel is closed and drained (returns None), or the enclosing concurrent block’s context fires (silent unwind). After close, any remaining buffered values are delivered to subsequent receive calls; thereafter every call returns None.

fn close(ch: Channel<'T>): Unit

type function on Channel

Close the channel. Subsequent send calls return Err(ChannelClosed); pending blocked sends panic at runtime (the program is responsible for sequencing close so there are no blocked senders at close time). Double-close is a runtime error.

impl Debug

fn inspect<'T>(value: Channel<'T>): String where 'T: Debug

impl Debug.inspect

type ChannelClosed

Returned by Channel.send when the channel was closed at the time the send attempted to enqueue. Channel.close itself is a one-shot operation (panics on double-close, matching Go); user code should plan shutdown so close happens exactly once.

impl Debug

fn inspect(value: ChannelClosed): String

impl Debug.inspect