Skip to content

Instantly share code, notes, and snippets.


jkramer/workshop.p6 Secret

Created Jun 29, 2018
What would you like to do?
my $checkpoint =;
my $total-workers = 5;
my $units-to-build = 3;
await (1..$total-workers).map: {
start {
my $id = $_;
my %who's-ready;
my $go =;
$checkpoint.Supply.tap: {
die "Oh no, something's wrong!" if %who's-ready{$_}:exists;
%who's-ready{$_} = True;
if %who's-ready == $total-workers {
$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;
say "All work is done!";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment