Qu

channel_recv

Builtin index · Concurrency

result = channel_recv(ch)

Input: ch · Output: result

What it is

Blocks the calling thread until a value is available on channel ch, then pops and returns it (FIFO — oldest channel_sendd value first).

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = channel_recv(ch)
ch —not documented yet
result —
Returns the sent value itself — whatever type the matching channel_send put in.

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_recv(ch) — blocks until a value is available, then pops and returns it (FIFO).

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