+sub check_async_step ($$) {
+ my ($self, $inflight_c) = @_;
+ die 'BUG: inflight empty or odd' if scalar(@$inflight_c) < 3;
+ my ($req, $cb, $arg) = splice(@$inflight_c, 0, 3);
+ my $rbuf = delete($self->{rbuf_c}) // \(my $new = '');
+ chomp(my $line = my_readline($self->{in_c}, $rbuf));
+ my ($hex, $type, $size) = split(/ /, $line);
+
+ # Future versions of git.git may have type=ambiguous, but for now,
+ # we must handle 'dangling' below (and maybe some other oddball
+ # stuff):
+ # https://public-inbox.org/git/20190118033845.s2vlrb3wd3m2jfzu@dcvr/T/
+ if ($hex eq 'dangling' || $hex eq 'notdir' || $hex eq 'loop') {
+ my $ret = my_read($self->{in_c}, $rbuf, $type + 1);
+ fail($self, defined($ret) ? 'read EOF' : "read: $!") if !$ret;
+ }
+ eval { $cb->($hex, $type, $size, $arg, $self) };
+ warn "E: check($req) $@\n" if $@;
+ $self->{rbuf_c} = $rbuf if $$rbuf ne '';
+}
+
+sub check_async_wait ($) {
+ my ($self) = @_;
+ my $inflight_c = delete $self->{inflight_c} or return;
+ while (scalar(@$inflight_c)) {
+ check_async_step($self, $inflight_c);