Last active
March 4, 2018 16:50
-
-
Save Altai-man/b5b71a7418590b4ac7ac58979d93f171 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; | |
my $end = $c.closed; | |
# Example of task to keep channel busy | |
supply { # Don't forget to pull items from the channel, otherwise $close will not be kept. | |
for (0..2) { {$c.close;done} if $_ == 2; .say; sleep 0.5; } | |
}.tap; | |
my $timeout = Promise.in(5); | |
my $timeout-or-good = Promise.anyof($end, $timeout); | |
await $timeout-or-good.then( | |
{ | |
if $timeout.status ~~ Kept { | |
'too bad'.say; | |
} else { | |
'good'.say | |
} | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment