Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@zoffixznet
Created August 5, 2016 15:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zoffixznet/a1a8a508659bd214b9868a13a0bcc6a6 to your computer and use it in GitHub Desktop.
Save zoffixznet/a1a8a508659bd214b9868a13a0bcc6a6 to your computer and use it in GitHub Desktop.
my $c = Channel.new;
# Start five Promises that sleep for 1..5 seconds, and then
# send a value to our Channel
(1..5).map: -> $v {
start {
sleep $v;
$c.send: "$v from thread {$*THREAD.id}";
$c.close if $v == 5;
CATCH { default { warn $_; warn .backtrace } }
}
}
# Continuously loop and poll the channel, until it's closed
loop {
if $c.poll -> $item {
say "$item received after {now - INIT now} seconds";
}
elsif $c.closed {
last;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment