Skip to content

Instantly share code, notes, and snippets.

@jnthn

jnthn/worker.p6 Secret

Created February 16, 2016 18:14
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jnthn/e1f8e086dd4d6387cce3 to your computer and use it in GitHub Desktop.
sub worker() {
react {
my $current-proc;
whenever Promise.in(5) {
say "Timed out!";
$current-proc.?kill;
done;
}
my @tasks =
{
$current-proc = Proc::Async.new('calc.exe');
$current-proc.start
},
{
say "doing some work";
},
{
$current-proc = Proc::Async.new('calc.exe');
$current-proc.start;
};
sub next-task() {
done unless @tasks;
my $running = @tasks.shift.();
if $running ~~ Promise {
whenever $running {
$current-proc = Nil;
next-task();
}
}
else {
next-task();
}
}
next-task();
}
}
worker();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment