Created
August 5, 2016 15:55
-
-
Save zoffixznet/f2cf979cef1f2fd0c4006b25939ee12d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 5 - $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