Skip to content

Instantly share code, notes, and snippets.

@jonathanstowe
Created June 8, 2015 16:53
Show Gist options
  • Save jonathanstowe/a93e637ef971e7eac92a to your computer and use it in GitHub Desktop.
Save jonathanstowe/a93e637ef971e7eac92a to your computer and use it in GitHub Desktop.
Async gather
(
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)
@jonathanstowe
Copy link
Author

That's much nicer :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment