use strict;
use warnings;
use base qw(PublicInbox::DS);
-use fields qw(cb end);
+use fields qw(cb arg end end_arg);
use Errno qw(EAGAIN);
use PublicInbox::Syscall qw(EPOLLIN EPOLLET);
# $io is a read-only pipe ($rpipe) for now, but may be a
# bidirectional socket in the future.
sub new {
- my ($class, $io, $cb, $end) = @_;
+ my ($class, $io, $cb, $arg, $end, $end_arg) = @_;
# no $io? call $cb at the top of the next event loop to
# avoid recursion:
unless (defined($io)) {
- PublicInbox::DS::requeue($cb);
+ PublicInbox::DS::requeue($cb ? $cb : $arg);
die '$end unsupported w/o $io' if $end;
return;
}
IO::Handle::blocking($io, 0);
$self->SUPER::new($io, EPOLLIN | EPOLLET);
$self->{cb} = $cb; # initial read callback, later replaced by main_cb
+ $self->{arg} = $arg; # arg for $cb
$self->{end} = $end; # like END {}, but only for this object
+ $self->{end_arg} = $end_arg; # arg for $end
$self;
}
($rpipe) = @_; # popen_rd result
if ($async) {
# PublicInbox::HTTPD::Async->new($rpipe, $cb, $end)
- $async = $async->($rpipe, $cb, $end);
+ $async = $async->($rpipe, $cb, undef, $end);
# $cb will call ->async_pass or ->close
} else { # generic PSGI
$cb->() while $qx;
($rpipe) = @_;
if ($async) {
# PublicInbox::HTTPD::Async->new($rpipe, $cb, $end)
- $async = $async->($rpipe, $cb, $end);
+ $async = $async->($rpipe, $cb, undef, $end);
# $cb will call ->async_pass or ->close
} else { # generic PSGI
$cb->() while $rd_hdr;
$user_cb->(undef);
}
-sub do_step ($) {
+sub event_step ($) {
my ($self) = @_;
eval {
# step 1: resolve blobs to patches in the todo queue
}
}
-sub step_cb ($) {
- my ($self) = @_;
- sub { do_step($self) };
-}
-
sub next_step ($) {
my ($self) = @_;
# if outside of public-inbox-httpd, caller is expected to be
- # looping step_cb, anyways
+ # looping event_step, anyways
my $async = $self->{psgi_env}->{'pi-httpd.async'} or return;
# PublicInbox::HTTPD::Async->new
- $async->(undef, step_cb($self));
+ $async->(undef, undef, $self);
}
sub mark_found ($$$) {
$self->{tmp} = File::Temp->newdir("solver.$oid_want-XXXXXXXX", TMPDIR => 1);
dbg($self, "solving $oid_want ...");
- my $step_cb = step_cb($self);
if (my $async = $env->{'pi-httpd.async'}) {
# PublicInbox::HTTPD::Async->new
- $async->(undef, $step_cb);
+ $async->(undef, undef, $self);
} else {
- $step_cb->() while $self->{user_cb};
+ event_step($self) while $self->{user_cb};
}
}