Qu

channel_try_recv

Builtin index · Concurrency

result = channel_try_recv(ch)

Input: ch · Output: result

What it is

Non-blocking counterpart to channel_recv: returns none (Nothing) immediately if nothing is queued on channel ch right now, instead of waiting; otherwise pops and returns the next value the same way channel_recv would.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = channel_try_recv(ch)
ch —not documented yet
result —
Returns the sent value itself, whatever type it is, or none when the channel is empty.

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()
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_try_recv(ch) — non-blocking: none if nothing is queued right now, instead of waiting.

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