Qu

channel_send

Builtin index · Concurrency

channel_send(ch, value)

Input: ch, value · Output: no output

What it is

Pushes value (any value, any type) onto channel ch's queue and wakes one waiting channel_recv.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
channel_send(ch, value)
ch —not documented yet
value —not documented yet
no output—

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_send(ch, value) — push a value onto the queue and wake one waiting channel_recv. Never blocks (unbounded queue — a bounded, back-pressured version is a real follow-up if an unbounded producer ever proves to be a problem in practice; not attempted here since nothing in this codebase's own worker patterns needs it yet).

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