Course of Raku / Functional, concurrent, reactive, and web programming / Concurrent programming / Channels / Closing a channel

Quiz — Closing a channel

What does the following program print?

my $c = Channel.new;
$c.send(1);
$c.send(2);
$c.close;
say $c.list.elems;
00
01
12
0it waits forever

.list collects every value still in the channel and finishes because the channel is closed. Two values were sent, so .elems is 2. Without the .close, .list would wait forever.

Course navigation

Closing a channel   |   Receive a value