From 74bbc3da398d00ba12e9294e360ad177ab2061ed Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 24 May 2016 03:41:51 +0000 Subject: standardize timer-related event-loop code Standardize the code we have in place to avoid creating too many timer objects. We do not need exact timers for things that don't need to be run ASAP, so we can play things fast and loose to avoid wasting power with unnecessary wakeups. We only need two classes of timers: * asap - run this on the next loop tick, after operating on @Danga::Socket::ToClose to close remaining sockets * later - run at some point in the future. It could be as soon as immediately (like "asap"), and as late as 60s into the future. In the future, we support an "emergency" switch to fire "later" timers immediately. --- lib/PublicInbox/HTTPD/Async.pm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/PublicInbox/HTTPD') diff --git a/lib/PublicInbox/HTTPD/Async.pm b/lib/PublicInbox/HTTPD/Async.pm index bd2eacbf..47ba27d2 100644 --- a/lib/PublicInbox/HTTPD/Async.pm +++ b/lib/PublicInbox/HTTPD/Async.pm @@ -10,6 +10,7 @@ use strict; use warnings; use base qw(Danga::Socket); use fields qw(cb cleanup); +require PublicInbox::EvCleanup; sub new { my ($class, $io, $cb, $cleanup) = @_; @@ -61,7 +62,7 @@ sub close { $self->SUPER::close(@_); # we defer this to the next timer loop since close is deferred - Danga::Socket->AddTimer(0, $cleanup) if $cleanup; + PublicInbox::EvCleanup::asap($cleanup) if $cleanup; } # do not let ourselves be closed during graceful termination -- cgit v1.2.3-24-ge0c7