Created
August 5, 2016 15:56
-
-
Save zoffixznet/a1a8a508659bd214b9868a13a0bcc6a6 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 $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