From 2686f6e69245aa32f9c2a286475ed91db776b065 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 17 Oct 2020 08:04:24 +0000 Subject: git: introduce async_wait_all ->cat_async and ->check_async may trigger each other (in future callers) while waiting, so we need a unified method to ensure both complete. This doesn't affect current code, but allows us to slightly simplify existing callers. --- lib/PublicInbox/Git.pm | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'lib/PublicInbox/Git.pm') diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm index e3a2bcb8..86343ac9 100644 --- a/lib/PublicInbox/Git.pm +++ b/lib/PublicInbox/Git.pm @@ -352,13 +352,23 @@ sub qx { <$fh> } +# check_async and cat_async may trigger the other, so ensure they're +# both completely done by using this: +sub async_wait_all ($) { + my ($self) = @_; + while (scalar(@{$self->{inflight_c} // []}) || + scalar(@{$self->{inflight} // []})) { + $self->check_async_wait; + $self->cat_async_wait; + } +} + # returns true if there are pending "git cat-file" processes sub cleanup { my ($self) = @_; local $in_cleanup = 1; delete $self->{async_cat}; - check_async_wait($self); - cat_async_wait($self); + async_wait_all($self); delete $self->{inflight}; delete $self->{inflight_c}; _destroy($self, qw(cat_rbuf in out pid)); -- cgit v1.2.3-24-ge0c7