Skip to content

Instantly share code, notes, and snippets.

@Altai-man
Last active March 4, 2018 16:50
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 Altai-man/b5b71a7418590b4ac7ac58979d93f171 to your computer and use it in GitHub Desktop.
Save Altai-man/b5b71a7418590b4ac7ac58979d93f171 to your computer and use it in GitHub Desktop.
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