- foreach my $ary (@$tmp) {
- my ($pid, $cb, $arg) = @$ary;
- my $ret = waitpid($pid, WNOHANG);
- if ($ret == 0) {
- push @$wait_pids, $ary; # autovivifies @$wait_pids
- } elsif ($ret == $pid) {
- if ($cb) {
- eval { $cb->($arg, $pid) };
- warn "E: dwaitpid($pid) in_loop: $@" if $@;
- }
+ while (1) {
+ my $pid = waitpid(-1, WNOHANG) // last;
+ last if $pid <= 0;
+ if (defined(my $cb_args = delete $AWAIT_PIDS->{$pid})) {
+ await_cb($pid, @$cb_args) if $cb_args;