about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/PublicInbox/EvCleanup.pm9
-rw-r--r--lib/PublicInbox/HTTPD/Async.pm2
2 files changed, 10 insertions, 1 deletions
diff --git a/lib/PublicInbox/EvCleanup.pm b/lib/PublicInbox/EvCleanup.pm
index 61837b89..2b77c617 100644
--- a/lib/PublicInbox/EvCleanup.pm
+++ b/lib/PublicInbox/EvCleanup.pm
@@ -9,6 +9,7 @@ use base qw(Danga::Socket);
 use fields qw(rd);
 my $singleton;
 my $asapq = [ [], undef ];
+my $nextq = [ [], undef ];
 my $laterq = [ [], undef ];
 
 sub once_init () {
@@ -30,6 +31,7 @@ sub _run_all ($) {
 }
 
 sub _run_asap () { _run_all($asapq) }
+sub _run_next () { _run_all($nextq) }
 sub _run_later () { _run_all($laterq) }
 
 # Called by Danga::Socket
@@ -51,6 +53,12 @@ sub asap ($) {
         $asapq->[1] ||= _asap_timer();
 }
 
+sub next_tick ($) {
+        my ($cb) = @_;
+        push @{$nextq->[0]}, $cb;
+        $nextq->[1] ||= Danga::Socket->AddTimer(0, *_run_next);
+}
+
 sub later ($) {
         my ($cb) = @_;
         push @{$laterq->[0]}, $cb;
@@ -59,6 +67,7 @@ sub later ($) {
 
 END {
         _run_asap();
+        _run_next();
         _run_later();
 }
 
diff --git a/lib/PublicInbox/HTTPD/Async.pm b/lib/PublicInbox/HTTPD/Async.pm
index 880cf021..68514f5a 100644
--- a/lib/PublicInbox/HTTPD/Async.pm
+++ b/lib/PublicInbox/HTTPD/Async.pm
@@ -72,7 +72,7 @@ sub close {
         $self->SUPER::close(@_);
 
         # we defer this to the next timer loop since close is deferred
-        PublicInbox::EvCleanup::asap($cleanup) if $cleanup;
+        PublicInbox::EvCleanup::next_tick($cleanup) if $cleanup;
 }
 
 1;