]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
qspawn: better annotate where $qx_cb is called
authorEric Wong <e@80x24.org>
Sat, 21 Jan 2017 02:29:50 +0000 (02:29 +0000)
committerEric Wong <e@80x24.org>
Sat, 21 Jan 2017 02:30:06 +0000 (02:30 +0000)
Hopefully this makes the code easier-to-follow for random
readers.  This requires a small amount of modification to
our one caller, but this is a new, unstable API (as is
nearly all of our code).

lib/PublicInbox/Qspawn.pm
lib/PublicInbox/RepobrowseGitSnapshot.pm

index da770cc045f5cfb62913007ba348bd232c41e45a..73022656c2b4aef8ff421639ef54de3c61589fae 100644 (file)
@@ -74,10 +74,10 @@ sub _psgi_finish ($$) {
 
 sub psgi_qx {
        my ($self, $env, $limiter, $qx_cb) = @_;
-       my $qx = PublicInbox::Qspawn::Qx->new($qx_cb);
+       my $qx = PublicInbox::Qspawn::Qx->new;
        my $end = sub {
                _psgi_finish($self, $env);
-               $qx->close;
+               eval { $qx_cb->($qx) };
                $qx = undef;
        };
        my $rpipe;
@@ -196,19 +196,14 @@ use strict;
 use warnings;
 
 sub new {
-       my ($class, $cb) = @_;
-       bless [ '', $cb ], $class;
+       my ($class) = @_;
+       my $buf = '';
+       bless \$buf, $class;
 }
 
+# called by PublicInbox::HTTPD::Async ($fh->write)
 sub write {
-       $_[0]->[0] .= $_[1];
-       undef;
-}
-
-sub close {
-       my ($self) = @_;
-       my $cb = $self->[1];
-       eval { $cb->(\($self->[0])) };
+       ${$_[0]} .= $_[1];
        undef;
 }
 
index cceb4641e91aa81e99504a5936584da02cfafe11..a9751b97e0131f44d58f281fa0c782420d47a527 100644 (file)
@@ -87,7 +87,7 @@ sub call_git_snapshot ($$) { # invoked by PublicInbox::RepobrowseBase::call
        $env->{'qspawn.quiet'} = 1;
        my $tree_cb = $env->{'repobrowse.tree_cb'} = sub {
                my ($ref) = @_;
-               if (ref($ref) eq 'SCALAR') {
+               if (defined $ref) {
                        $tree = $$ref;
                        chomp $tree;
                }