Created
June 8, 2015 16:53
-
-
Save jonathanstowe/a93e637ef971e7eac92a to your computer and use it in GitHub Desktop.
Async gather
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
( | |
gather { | |
my $c = Channel.new; | |
my @ps = do for ^10 { start { sleep rand; $c.send($_) } }; | |
my $p = Promise.allof(@ps); | |
loop { | |
earliest $c { | |
more * { | |
take $_; | |
} | |
}; | |
last if $p; | |
} | |
await @ps; | |
}).map(*.say) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment