* [PATCH 06/13] ds: improve add_timer usability
2021-02-08 9:05 7% [PATCH 00/13] lei approxidate, startup fix, --alert Eric Wong
@ 2021-02-08 9:05 5% ` Eric Wong
0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2021-02-08 9:05 UTC (permalink / raw)
To: meta
Packing args into an arrayref is awkward and we may be using
this API more in lei.
---
lib/PublicInbox/DS.pm | 10 +++++-----
lib/PublicInbox/ExtSearchIdx.pm | 5 ++---
lib/PublicInbox/FakeInotify.pm | 4 ++--
lib/PublicInbox/Watch.pm | 19 ++++++++-----------
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 });
^ permalink raw reply related [relevance 5%]
* [PATCH 00/13] lei approxidate, startup fix, --alert
@ 2021-02-08 9:05 7% Eric Wong
2021-02-08 9:05 5% ` [PATCH 06/13] ds: improve add_timer usability Eric Wong
0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2021-02-08 9:05 UTC (permalink / raw)
To: meta
I've redone and squashed some changes into PATCH 1/13 which
was posted yesterday.
3/13 (SIGWINCH) is rebase necessary after 1/13,
4/13 (--alert=CMD) is a generalized take on 3/13.
12/13 is...
Eric Wong (13):
lei q: improve remote mboxrd UX + MUA
lei_xsearch: quiet Eml warnings from remote mboxrds
lei q: SIGWINCH process group with the terminal
lei q: support --alert=CMD for early MUA users
tests: favor IPv6
ds: improve add_timer usability
lei: start_pager: drop COLUMNS default
lei: avoid racing on unlink + bind + listen
lei: drop BSD::Resource usage
git: implement date_parse method
lei q: use git approxidate with d:, dt: and rt: ranges
search: use one git-rev-parse process for all dates
spawnpp: raise exception on E2BIG errors
lib/PublicInbox/DS.pm | 10 ++--
lib/PublicInbox/ExtSearchIdx.pm | 5 +-
lib/PublicInbox/FakeInotify.pm | 4 +-
lib/PublicInbox/Git.pm | 10 +++-
lib/PublicInbox/IPC.pm | 8 +--
lib/PublicInbox/LEI.pm | 100 ++++++++++++++++++++++----------
lib/PublicInbox/LeiCurl.pm | 11 +++-
lib/PublicInbox/LeiMirror.pm | 5 +-
lib/PublicInbox/LeiOverview.pm | 6 +-
lib/PublicInbox/LeiQuery.pm | 12 ++--
lib/PublicInbox/LeiToMail.pm | 24 ++++----
lib/PublicInbox/LeiXSearch.pm | 97 ++++++++++++++++++++-----------
lib/PublicInbox/Search.pm | 86 +++++++++++++++++++++++++++
lib/PublicInbox/SpawnPP.pm | 23 ++++++--
lib/PublicInbox/TestCommon.pm | 30 ++++++++--
lib/PublicInbox/Watch.pm | 19 +++---
script/lei | 16 ++---
t/extsearch.t | 2 +-
t/git.t | 17 +++++-
t/httpd-corner.psgi | 2 +-
t/httpd-corner.t | 12 ++--
t/httpd-https.t | 2 +-
t/httpd-unix.t | 7 +--
t/httpd.t | 8 +--
t/imapd-tls.t | 4 +-
t/imapd.t | 8 +--
t/lei-mirror.t | 2 +-
t/nntpd-tls.t | 4 +-
t/nntpd.t | 11 ++--
t/psgi_attach.t | 2 +-
t/psgi_v2.t | 2 +-
t/search.t | 51 ++++++++++++++++
t/solver_git.t | 2 +-
t/v2mirror.t | 3 +-
t/v2writable.t | 3 +-
t/www_altid.t | 2 +-
t/www_listing.t | 3 +-
xt/git-http-backend.t | 4 +-
xt/httpd-async-stream.t | 2 +-
xt/imapd-mbsync-oimap.t | 4 +-
xt/imapd-validate.t | 4 +-
xt/mem-imapd-tls.t | 2 +-
xt/nntpd-validate.t | 3 +-
xt/perf-nntpd.t | 16 ++---
xt/solver.t | 3 +-
45 files changed, 441 insertions(+), 210 deletions(-)
^ permalink raw reply [relevance 7%]
Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2021-02-08 9:05 7% [PATCH 00/13] lei approxidate, startup fix, --alert Eric Wong
2021-02-08 9:05 5% ` [PATCH 06/13] ds: improve add_timer usability Eric Wong
Code repositories for project(s) associated with this public inbox
https://80x24.org/public-inbox.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).