]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/HTTPD/Async.pm
qspawn: replace anonymous $end callbacks w/ event_step
[public-inbox.git] / lib / PublicInbox / HTTPD / Async.pm
index d182c11886c5f4b1557d9e0828469fcdb7ae7b28..8956f7198920a2e218ec5ec40a9e7a87cb3ab2df 100644 (file)
@@ -10,7 +10,7 @@ package PublicInbox::HTTPD::Async;
 use strict;
 use warnings;
 use base qw(PublicInbox::DS);
-use fields qw(cb arg end end_arg);
+use fields qw(cb arg end_obj);
 use Errno qw(EAGAIN);
 use PublicInbox::Syscall qw(EPOLLIN EPOLLET);
 
@@ -18,13 +18,13 @@ 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, $arg, $end, $end_arg) = @_;
+       my ($class, $io, $cb, $arg, $end_obj) = @_;
 
        # no $io? call $cb at the top of the next event loop to
        # avoid recursion:
        unless (defined($io)) {
                PublicInbox::DS::requeue($cb ? $cb : $arg);
-               die '$end unsupported w/o $io' if $end;
+               die '$end_obj unsupported w/o $io' if $end_obj;
                return;
        }
 
@@ -33,8 +33,7 @@ sub new {
        $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->{end_obj} = $end_obj; # like END{}, can ->event_step
        $self;
 }
 
@@ -98,8 +97,11 @@ sub close {
        $self->SUPER::close; # DS::close
 
        # we defer this to the next timer loop since close is deferred
-       if (my $end = delete $self->{end}) {
-               PublicInbox::DS::requeue($end);
+       if (my $end_obj = delete $self->{end_obj}) {
+               # this calls $end_obj->event_step
+               # (likely PublicInbox::Qspawn::event_step,
+               #  NOT PublicInbox::HTTPD::Async::event_step)
+               PublicInbox::DS::requeue($end_obj);
        }
 }