]> Sergey Matveev's repositories - public-inbox.git/commitdiff
ds: drop ::later support
authorEric Wong <e@80x24.org>
Wed, 29 Sep 2021 12:40:47 +0000 (07:40 -0500)
committerEric Wong <e@80x24.org>
Wed, 29 Sep 2021 19:58:08 +0000 (19:58 +0000)
add_uniq_timer seems sufficient, and we'll drop the last
user of ::later (IMAP) and switch to unique timers.

lib/PublicInbox/DS.pm
lib/PublicInbox/IMAP.pm

index a25e3fe8485738c565f7d8b4ba73a7dacc611b8c..37cd6087cafb2bd8009921f86c27d7de741c6125 100644 (file)
@@ -37,7 +37,6 @@ our @EXPORT_OK = qw(now msg_more dwaitpid add_timer add_uniq_timer);
 my %Stack;
 my $nextq; # queue for next_tick
 my $wait_pids; # list of [ pid, callback, callback_arg ]
-my $later_q; # list of callbacks to run at some later interval
 my $EXPMAP; # fd -> idle_time
 our $EXPTIME = 180; # 3 minutes
 my ($reap_armed);
@@ -78,11 +77,11 @@ sub Reset {
                my @q = delete @Stack{keys %Stack};
                for my $q (@q) { @$q = () }
                $EXPMAP = undef;
-               $wait_pids = $later_q = $nextq = $ToClose = undef;
+               $wait_pids = $nextq = $ToClose = undef;
                $_io = undef; # closes real $Epoll FD
                $Epoll = undef; # may call DSKQXS::DESTROY
        } while (@Timers || keys(%Stack) || $nextq || $wait_pids ||
-               $later_q || $ToClose || keys(%DescriptorMap) ||
+               $ToClose || keys(%DescriptorMap) ||
                $PostLoopCallback || keys(%UniqTimer));
 
        $reap_armed = undef;
@@ -298,7 +297,6 @@ sub EventLoop {
             $obj->event_step;
         }
     } while (PostEventLoop());
-    _run_later();
 }
 
 =head2 C<< CLASS->SetPostLoopCallback( CODEREF ) >>
@@ -658,19 +656,6 @@ sub dwaitpid ($;$$) {
        }
 }
 
-sub _run_later () {
-       my $q = $later_q or return;
-       $later_q = undef;
-       $Stack{later_q} = $q;
-       $_->() for @$q;
-       delete $Stack{later_q};
-}
-
-sub later ($) {
-       push @$later_q, $_[0]; # autovivifies @$later_q
-       add_uniq_timer('later', 60, \&_run_later);
-}
-
 sub expire_old () {
        my $cur = $EXPMAP or return;
        $EXPMAP = undef;
index 27013ea563c1148eee7be0dfc531f978e54c62bd..bc34f4feea1e8ae7b6fe1c1bc5956f1c0d5b3d4f 100644 (file)
@@ -316,20 +316,19 @@ sub on_inbox_unlock {
        }
 }
 
-# called every X minute(s) or so by PublicInbox::DS::later
-my $IDLERS = {};
-my $idle_timer;
+# called every minute or so by PublicInbox::DS::later
+my $IDLERS; # fileno($obj->{sock}) => PublicInbox::IMAP
 sub idle_tick_all {
        my $old = $IDLERS;
-       $IDLERS = {};
+       $IDLERS = undef;
        for my $i (values %$old) {
                next if ($i->{wbuf} || !exists($i->{-idle_tag}));
                $i->update_idle_time or next;
                $IDLERS->{fileno($i->{sock})} = $i;
                $i->write(\"* OK Still here\r\n");
        }
-       $idle_timer = scalar keys %$IDLERS ?
-                       PublicInbox::DS::later(\&idle_tick_all) : undef;
+       $IDLERS and
+               PublicInbox::DS::add_uniq_timer('idle', 60, \&idle_tick_all);
 }
 
 sub cmd_idle ($$) {
@@ -346,7 +345,7 @@ sub cmd_idle ($$) {
                $ibx->subscribe_unlock($fd, $self);
                $self->{imapd}->idler_start;
        }
-       $idle_timer //= PublicInbox::DS::later(\&idle_tick_all);
+       PublicInbox::DS::add_uniq_timer('idle', 60, \&idle_tick_all);
        $IDLERS->{$fd} = $self;
        \"+ idling\r\n"
 }