Raku Books / Perl 6 at a Glance / New Concepts / Channels

The list method

The list method accompanies the previously seen methods and returns everything that is left unread in the channel.

my $c = Channel.new;

$c.send(5);
$c.send(6);

$c.close;
say $c.list; # (5 6)

🧵 This program uses concurrency (promises, threads). The in-browser engine (Raku.js) is single-threaded and can’t run it yet — try it on your own computer.

The method blocks the programme until the channel is open, thus it is wise to close it before calling the list method.

Course navigation

← Read and write   |   Beyond scalars →