Skip to content

Instantly share code, notes, and snippets.

@jkramer jkramer/workshop.p6 Secret
Created Jun 29, 2018

Embed
What would you like to do?
my $checkpoint = Supplier.new;
my $total-workers = 5;
my $units-to-build = 3;
await (1..$total-workers).map: {
start {
my $id = $_;
my %who's-ready;
my $go = Channel.new;
$checkpoint.Supply.tap: {
die "Oh no, something's wrong!" if %who's-ready{$_}:exists;
%who's-ready{$_} = True;
if %who's-ready == $total-workers {
%who's-ready{*}:delete;
$go.send: Any;
}
};
for ^$units-to-build {
my $duration = 3.rand;
say "$id starts working for $duration seconds.";
sleep $duration;
say "$id is done, waiting.";
$checkpoint.emit: $id;
$go.receive;
}
}
}
say "All work is done!";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.