In Channel§
See primary documentation in context for method poll.
method poll(Channel:D:)
Receives and removes an item from the Channel. If no item is present, returns Nil instead of waiting.
my $c = Channel.new; Promise.in(2).then: { $c.close; } ^10 .map({ $c.send($_); }); loop { if $c.poll -> $item { $item.say }; if $c.closed { last }; sleep 0.1; }
See method receive for a blocking version that properly responds to Channel closing and failure.