I have a perl6 program that runs a external program via Proc::Async and tries to read its stdout. It's possible that the portion of the code that is supposed to read the stdout somehow fails to do so, but other parts of the program will actually kill the external process in order to clean things up. However, after killing such process, and then await the promise, it blocks forever..., how can I avoid perl6 from blocking on awaiting a killed Proc::Async whose stdout is piped but not consumed? I think the following snippet illustrate the problem:
#!/usr/bin/env perl6
#
my $proc = Proc::Async.new(<cat /dev/urandom>);
my $supply = $proc.stdout(:bin);
my $promise = $proc.start;
$proc.ready.then: {
shell <<ps auxf | grep [u]random>>;
put "Terminating process {$_.result} …";
$proc.kill(SIGTERM);
}
sleep 1;
if shell(<<ps auxf | grep [u]random>>).exitcode ≠ 0 {
put "processed killed!";
}
put "awaiting $proc ({$proc.command}) …";
await $promise; # <--- blocked here :(