use PublicInbox::Spawn qw(popen_rd);
use IO::Handle ();
use PublicInbox::Syscall qw(EPOLLONESHOT);
+use PublicInbox::DS qw(dwaitpid);
# fields:
# async_cat => GitAsyncCat ref (read-only pipe)
# sock => writable pipe to Gcf2::loop
sub DESTROY {
my ($self) = @_;
- my $pid = delete $self->{pid};
delete $self->{in};
- return unless $pid;
- eval {
- PublicInbox::DS::dwaitpid($pid, undef, undef);
- $self->close; # we're still in the event loop
- };
- if ($@) { # wait synchronously if not in event loop
- my $sock = delete $self->{sock};
- close $sock if $sock;
- waitpid($pid, 0);
- }
+ # GitAsyncCat::event_step may reap us with WNOHANG, too
+ my $pid = delete $self->{pid} or return;
+ PublicInbox::DS->in_loop ? $self->close : delete($self->{sock});
+ dwaitpid $pid;
}
# used by GitAsyncCat