+ my $running = --$limiter->{running};
+
+ # limiter->{max} may change dynamically
+ if (($running || $limiter->{running}) < $limiter->{max}) {
+ if (my $next = shift @{$limiter->{run_queue}}) {
+ _do_spawn(@$next);
+ }
+ }
+
+ return unless $err;
+ $self->{err} = $err;
+ my $env = $self->{env} or return;
+ if (!$env->{'qspawn.quiet'}) {
+ $err = join(' ', @{$self->{args}->[0]}).": $err\n";
+ $env->{'psgi.errors'}->print($err);
+ }
+}
+
+sub do_waitpid ($;$) {
+ my ($self, $env) = @_;
+ my $pid = $self->{pid};
+ eval { # PublicInbox::DS may not be loaded
+ PublicInbox::DS::dwaitpid($pid, \&waitpid_err, $self);
+ $self->{env} = $env;
+ };
+ # done if we're running in PublicInbox::DS::EventLoop
+ if ($@) {
+ # non public-inbox-{httpd,nntpd} callers may block:
+ my $ret = waitpid($pid, 0);
+ waitpid_err($self, $ret);
+ }
+}
+
+sub finish ($;$) {
+ my ($self, $env) = @_;