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 ]
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;
# 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:
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 {
$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);
}
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;
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;
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;
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);
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
}
}
-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);
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 ($$) {
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 });