about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-02-07 23:05:14 -1000
committerEric Wong <e@80x24.org>2021-02-08 22:07:44 +0000
commit22d0454088da756ed34d0e26d060955512ce7587 (patch)
tree2b5d78b5a12906788460fe714515c67ac1cd1b7b /lib
parent860169adcd29341142b7c4a369c09b4ac492bd1e (diff)
downloadpublic-inbox-22d0454088da756ed34d0e26d060955512ce7587.tar.gz
Packing args into an arrayref is awkward and we may be using
this API more in lei.
Diffstat (limited to 'lib')
-rw-r--r--lib/PublicInbox/DS.pm10
-rw-r--r--lib/PublicInbox/ExtSearchIdx.pm5
-rw-r--r--lib/PublicInbox/FakeInotify.pm4
-rw-r--r--lib/PublicInbox/Watch.pm19
4 files changed, 17 insertions, 21 deletions
diff --git a/lib/PublicInbox/DS.pm b/lib/PublicInbox/DS.pm
index ec965abe..e5f36bc5 100644
--- a/lib/PublicInbox/DS.pm
+++ b/lib/PublicInbox/DS.pm
@@ -33,7 +33,7 @@ use PublicInbox::Syscall qw(:epoll);
 use PublicInbox::Tmpfile;
 use Errno qw(EAGAIN EINVAL);
 use Carp qw(carp);
-our @EXPORT_OK = qw(now msg_more dwaitpid);
+our @EXPORT_OK = qw(now msg_more dwaitpid add_timer);
 
 my $nextq; # queue for next_tick
 my $wait_pids; # list of [ pid, callback, callback_arg ]
@@ -96,12 +96,12 @@ Add a timer to occur $seconds from now. $seconds may be fractional, but timers
 are not guaranteed to fire at the exact time you ask for.
 
 =cut
-sub add_timer ($$;$) {
-    my ($secs, $coderef, $arg) = @_;
+sub add_timer ($$;@) {
+    my ($secs, $coderef, @args) = @_;
 
     my $fire_time = now() + $secs;
 
-    my $timer = [$fire_time, $coderef, $arg];
+    my $timer = [$fire_time, $coderef, @args];
 
     if (!@Timers || $fire_time >= $Timers[-1][0]) {
         push @Timers, $timer;
@@ -184,7 +184,7 @@ sub RunTimers {
     # Run expired timers
     while (@Timers && $Timers[0][0] <= $now) {
         my $to_run = shift(@Timers);
-        $to_run->[1]->($to_run->[2]);
+        $to_run->[1]->(@$to_run[2..$#$to_run]);
     }
 
     # timers may enqueue into nextq:
diff --git a/lib/PublicInbox/ExtSearchIdx.pm b/lib/PublicInbox/ExtSearchIdx.pm
index 9b7340df..a4b3bbd5 100644
--- a/lib/PublicInbox/ExtSearchIdx.pm
+++ b/lib/PublicInbox/ExtSearchIdx.pm
@@ -29,7 +29,7 @@ use PublicInbox::V2Writable;
 use PublicInbox::InboxWritable;
 use PublicInbox::ContentHash qw(content_hash);
 use PublicInbox::Eml;
-use PublicInbox::DS qw(now);
+use PublicInbox::DS qw(now add_timer);
 use DBI qw(:sql_types); # SQL_BLOB
 
 sub new {
@@ -1027,8 +1027,7 @@ sub on_inbox_unlock { # called by PublicInbox::InboxIdle
         $pr->("indexing $ekey\n") if $pr;
         $self->idx_init($opt);
         sync_inbox($self, $self->{-watch_sync}, $ibx);
-        $self->{-commit_timer} //= PublicInbox::DS::add_timer(
-                                        $opt->{'commit-interval'} // 10,
+        $self->{-commit_timer} //= add_timer($opt->{'commit-interval'} // 10,
                                         \&_watch_commit, $self);
 }
 
diff --git a/lib/PublicInbox/FakeInotify.pm b/lib/PublicInbox/FakeInotify.pm
index 326b2391..25818e07 100644
--- a/lib/PublicInbox/FakeInotify.pm
+++ b/lib/PublicInbox/FakeInotify.pm
@@ -6,7 +6,7 @@
 package PublicInbox::FakeInotify;
 use strict;
 use Time::HiRes qw(stat);
-use PublicInbox::DS;
+use PublicInbox::DS qw(add_timer);
 sub IN_MODIFY () { 0x02 } # match Linux inotify
 # my $IN_MOVED_TO = 0x80;
 # my $IN_CREATE = 0x100;
@@ -66,7 +66,7 @@ sub read {
 sub poll_once {
         my ($obj) = @_;
         $obj->event_step; # PublicInbox::InboxIdle::event_step
-        PublicInbox::DS::add_timer($poll_intvl, \&poll_once, $obj);
+        add_timer($poll_intvl, \&poll_once, $obj);
 }
 
 package PublicInbox::FakeInotify::Watch;
diff --git a/lib/PublicInbox/Watch.pm b/lib/PublicInbox/Watch.pm
index 185e5da8..1835fa0e 100644
--- a/lib/PublicInbox/Watch.pm
+++ b/lib/PublicInbox/Watch.pm
@@ -11,7 +11,7 @@ use PublicInbox::InboxWritable qw(eml_from_path);
 use PublicInbox::Filter::Base qw(REJECT);
 use PublicInbox::Spamcheck;
 use PublicInbox::Sigfd;
-use PublicInbox::DS qw(now);
+use PublicInbox::DS qw(now add_timer);
 use PublicInbox::MID qw(mids);
 use PublicInbox::ContentHash qw(content_hash);
 use PublicInbox::EOFpipe;
@@ -590,8 +590,8 @@ sub watch_atfork_parent ($) {
         PublicInbox::DS::block_signals();
 }
 
-sub imap_idle_requeue ($) { # DS::add_timer callback
-        my ($self, $url_intvl) = @{$_[0]};
+sub imap_idle_requeue { # DS::add_timer callback
+        my ($self, $url_intvl) = @_;
         return if $self->{quit};
         push @{$self->{idle_todo}}, $url_intvl;
         event_step($self);
@@ -605,8 +605,7 @@ sub imap_idle_reap { # PublicInbox::DS::dwaitpid callback
         my ($url, $intvl) = @$url_intvl;
         return if $self->{quit};
         warn "W: PID=$pid on $url died: \$?=$?\n" if $?;
-        PublicInbox::DS::add_timer(60,
-                                \&imap_idle_requeue, [ $self, $url_intvl ]);
+        add_timer(60, \&imap_idle_requeue, $self, $url_intvl);
 }
 
 sub reap { # callback for EOFpipe
@@ -700,8 +699,8 @@ sub watch_nntp_fetch_all ($$) {
         }
 }
 
-sub poll_fetch_fork ($) { # DS::add_timer callback
-        my ($self, $intvl, $urls) = @{$_[0]};
+sub poll_fetch_fork { # DS::add_timer callback
+        my ($self, $intvl, $urls) = @_;
         return if $self->{quit};
         pipe(my ($r, $w)) or die "pipe: $!";
         my $oldset = watch_atfork_parent($self);
@@ -736,8 +735,7 @@ sub poll_fetch_reap {
                 warn "W: PID=$pid died: \$?=$?\n", map { "$_\n" } @$urls;
         }
         warn("I: will check $_ in ${intvl}s\n") for @$urls;
-        PublicInbox::DS::add_timer($intvl, \&poll_fetch_fork,
-                                        [$self, $intvl, $urls]);
+        add_timer($intvl, \&poll_fetch_fork, $self, $intvl, $urls);
 }
 
 sub watch_imap_init ($$) {
@@ -1013,8 +1011,7 @@ sub watch { # main entry point
         watch_nntp_init($self, $poll) if $self->{nntp};
         while (my ($intvl, $urls) = each %$poll) {
                 # poll all URLs for a given interval sequentially
-                PublicInbox::DS::add_timer(0, \&poll_fetch_fork,
-                                                [$self, $intvl, $urls]);
+                add_timer(0, \&poll_fetch_fork, $self, $intvl, $urls);
         }
         watch_fs_init($self) if $self->{mdre};
         PublicInbox::DS->SetPostLoopCallback(sub { !$self->quit_done });