Skip to content

Instantly share code, notes, and snippets.

@jnthn
Created July 10, 2013 23:14
Show Gist options
  • Save jnthn/5971100 to your computer and use it in GitHub Desktop.
Save jnthn/5971100 to your computer and use it in GitHub Desktop.
say "Creating a couple of threads...";
my $t1 = Thread.start({ sleep 1; say "Thread 1 done"; });
my $t2 = Thread.start({ sleep 2; say "Thread 2 done"; });
say "Waiting for joins...";
.join for $t1, $t2;
say "Joined!";
say "---";
say "Creating two promises...";
my $a = async { sleep 2; say "omg slept 2"; 27 }
my $b = async { sleep 1; say "omg slept 1"; 15 }
say "Scheduler has $*SCHEDULER.outstanding() tasks";
say "Waiting for results...";
say $a.result + $b.result;
say "---";
my $start = now;
my @line_counters = dir('docs/announce').map({
async {
say "Reading $_";
my $lines = $_.IO.lines.elems;
say "Done $_";
$lines
}
});
say [+] @line_counters.map(*.result);
say now - $start;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment