Skip to content

Instantly share code, notes, and snippets.

@MasterDuke17
Created April 11, 2019 21:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MasterDuke17/c18483f2d851760014042931779529b0 to your computer and use it in GitHub Desktop.
Save MasterDuke17/c18483f2d851760014042931779529b0 to your computer and use it in GitHub Desktop.
for "9.sh".IO.lines.kv -> $i, $oneliner {
say "line $i: $oneliner";
my $proc = Proc::Async.new: '/home/dan/p6/install/bin/perl6-m', '-e', $oneliner;
react {
whenever $proc.Supply { # chunks
say ‘output: ’, $_;
}
whenever $proc.start {
say ‘Proc finished: exitcode=’, .exitcode, ‘ signal=’, .signal;
done # gracefully jump from the react block
}
whenever signal(SIGTERM).merge: signal(SIGINT) {
once {
say ‘Signal received, asking the process to stop’;
$proc.kill; # sends SIGHUP, change appropriately
whenever signal($_).zip: Promise.in(2).Supply {
say ‘Kill it!’;
$proc.kill: SIGKILL
}
}
}
whenever Promise.in(20) {
say ‘Timeout. Asking the process to stop’;
$proc.kill; # sends SIGHUP, change appropriately
whenever Promise.in(2) {
say ‘Timeout. Forcing the process to stop’;
$proc.kill: SIGKILL
}
}
}
}
say ‘Program finished’;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment