Qu

channel

Builtin index · Concurrency

result = channel()

Input: no input · Output: result

What it is

Takes no arguments. Creates a new, empty channel.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = channel()no input
result Channel
Returns a Channel handle (type(ch) == "channel"); cloning it shares the same underlying queue, not a separate copy.

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

ch = channel()
producer() := channel_send(ch, 42)
w = spawn("producer")
value = channel_recv(ch)               # blocks until producer sends

print(value)                           # 42

join(w)
output
42

from concurrency

ch = channel()
print(channel_try_recv(ch))            # none -- nothing queued yet

channel_send(ch, 1)
channel_send(ch, 2)
print(channel_len(ch))                 # 2

print(channel_recv(ch))                # 1 (FIFO)

output
none
2
1

from concurrency

How it works

channel() — worker-to-worker communication (2026-08-24, worker-pool pass), the message-passing counterpart to mutex's shared-state: a blocking MPMC queue any worker holding the same channel can send into or receive from. Unlike mutex, no snapshot-time copy is needed to "give" a worker a channel — cloning a Value::Channel (which happens automatically when it's captured into a spawn/pmap/ parallel for env snapshot, same as any other variable) shares the same underlying queue, the same Arc-sharing convention Mutex/Semaphore/Timer already use.

From the note above this builtin in the interpreter, where the reasoning was written down as it was built.