about summary refs log tree commit homepage
path: root/lib/PublicInbox/Qspawn.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2019-09-17 08:31:21 +0000
committerEric Wong <e@80x24.org>2019-09-17 08:31:46 +0000
commitdce9ca5f952b0fe50caa2ac4e59c85139a17cfca (patch)
treefc356e3c39dbaf9d00b69ac5e75da41a239b05f7 /lib/PublicInbox/Qspawn.pm
parent685da5f572042faa54fb4479c222d4f2d258e2ed (diff)
downloadpublic-inbox-dce9ca5f952b0fe50caa2ac4e59c85139a17cfca.tar.gz
Naming $start_cb consistently helps avoid confusing new readers,
and some comments will help with understanding flow
Diffstat (limited to 'lib/PublicInbox/Qspawn.pm')
-rw-r--r--lib/PublicInbox/Qspawn.pm16
1 files changed, 9 insertions, 7 deletions
diff --git a/lib/PublicInbox/Qspawn.pm b/lib/PublicInbox/Qspawn.pm
index 10fe5341..5a300644 100644
--- a/lib/PublicInbox/Qspawn.pm
+++ b/lib/PublicInbox/Qspawn.pm
@@ -44,7 +44,7 @@ sub new ($$$;) {
 }
 
 sub _do_spawn {
-        my ($self, $cb, $limiter) = @_;
+        my ($self, $start_cb, $limiter) = @_;
         my $err;
         my ($cmd, $env, $opts) = @{$self->{args}};
         my %opts = %{$opts || {}};
@@ -66,7 +66,7 @@ sub _do_spawn {
         } else {
                 $self->{err} = $!;
         }
-        $cb->($self->{rpipe});
+        $start_cb->($self->{rpipe});
 }
 
 sub child_err ($) {
@@ -135,11 +135,11 @@ sub finish ($;$) {
 }
 
 sub start {
-        my ($self, $limiter, $cb) = @_;
+        my ($self, $limiter, $start_cb) = @_;
         if ($limiter->{running} < $limiter->{max}) {
-                _do_spawn($self, $cb, $limiter);
+                _do_spawn($self, $start_cb, $limiter);
         } else {
-                push @{$limiter->{run_queue}}, [ $self, $cb ];
+                push @{$limiter->{run_queue}}, [ $self, $start_cb ];
         }
 }
 
@@ -175,11 +175,12 @@ reread:
                 }
         };
         $limiter ||= $def_limiter ||= PublicInbox::Qspawn::Limiter->new(32);
-        $self->start($limiter, sub { # may run later, much later...
+        $self->start($limiter, sub { # start_cb, may run later, much later...
                 ($rpipe) = @_; # popen_rd result
                 if ($async) {
                 # PublicInbox::HTTPD::Async->new($rpipe, $cb, $end)
                         $async = $async->($rpipe, $cb, $end);
+                        # $cb will call ->async_pass or ->close
                 } else { # generic PSGI
                         $cb->() while $qx;
                 }
@@ -254,7 +255,7 @@ sub psgi_return {
                 $ret;
         };
 
-        my $wcb = delete $env->{'qspawn.wcb'};
+        my $wcb = delete $env->{'qspawn.wcb'}; # or PSGI server supplies it
         my $async = $env->{'pi-httpd.async'};
 
         my $cb = sub {
@@ -287,6 +288,7 @@ sub psgi_return {
                 if ($async) {
                         # PublicInbox::HTTPD::Async->new($rpipe, $cb, $end)
                         $async = $async->($rpipe, $cb, $end);
+                        # $cb will call ->async_pass or ->close
                 } else { # generic PSGI
                         $cb->() while $rd_hdr;
                 }