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

Solution: Drain a channel

Here is a possible solution to the task.

Code

my $c = Channel.new;
$c.send('a');
$c.send('b');
$c.close;

say $c.list.join(',');

🦋 You can find the source code in the file drain-channel.raku.

Output

a,b

Comments

  1. .list drains every value left in the closed channel, in order.

  2. .join(',') glues the two strings together with a comma between them.

Course navigation

Drain a channel   |   Hyper and race 🆕