Course of Raku / Functional, concurrent, reactive, and web programming / Concurrent programming / Channels / Receiving past the end

Quiz — Receiving past the end

A channel has had all its sent values received. What happens on the next .receive if the channel is still open (never closed)?

0It throws X::Channel::ReceiveOnClosed
1It blocks, waiting for a value that may never come
0It returns Nil
0It returns an empty list ()

On an open channel, .receive cannot tell whether another value is on its way, so it waits — potentially forever, if the producer has stopped without closing. The X::Channel::ReceiveOnClosed exception is the closed-channel case: only a closed, empty channel fails fast instead of blocking.

Course navigation

Receiving past the end   |   Receive a value