From 62bb26d307a106d6c9b42e36b583fd04d90a4687 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 27 Jun 2020 10:03:44 +0000 Subject: ds: add_timer: allow passing arg to callback. This allows callers to avoid creating expensive closures. We no longer pass the `$now' value to callers, as none of the callers used it. --- lib/PublicInbox/WatchMaildir.pm | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'lib/PublicInbox/WatchMaildir.pm') diff --git a/lib/PublicInbox/WatchMaildir.pm b/lib/PublicInbox/WatchMaildir.pm index b82b5102..f36aa20a 100644 --- a/lib/PublicInbox/WatchMaildir.pm +++ b/lib/PublicInbox/WatchMaildir.pm @@ -549,8 +549,8 @@ sub watch_imap_fetch_all ($$) { } } -sub imap_fetch_fork ($$$) { - my ($self, $intvl, $uris) = @_; +sub imap_fetch_fork ($) { # DS::add_timer callback + my ($self, $intvl, $uris) = @{$_[0]}; return if $self->{quit}; watch_atfork_parent($self); defined(my $pid = fork) or die "fork: $!"; @@ -563,11 +563,6 @@ sub imap_fetch_fork ($$$) { PublicInbox::DS::dwaitpid($pid, \&imap_fetch_reap, $self); } -sub imap_fetch_cb ($$$) { - my ($self, $intvl, $uris) = @_; - sub { imap_fetch_fork($self, $intvl, $uris) }; -} - sub imap_fetch_reap { # PublicInbox::DS::dwaitpid callback my ($self, $pid) = @_; my $intvl_uris = delete $self->{poll_pids}->{$pid} or @@ -579,7 +574,8 @@ sub imap_fetch_reap { # PublicInbox::DS::dwaitpid callback map { $_->as_string."\n" } @$uris; } warn('I: will check ', $_->as_string, " in ${intvl}s\n") for @$uris; - PublicInbox::DS::add_timer($intvl, imap_fetch_cb($self, $intvl, $uris)); + PublicInbox::DS::add_timer($intvl, \&imap_fetch_fork, + [$self, $intvl, $uris]); } sub watch_imap_init ($) { @@ -625,7 +621,8 @@ sub watch_imap_init ($) { # poll all URIs for a given interval sequentially while (my ($intvl, $uris) = each %$poll) { - PublicInbox::DS::requeue(imap_fetch_cb($self, $intvl, $uris)); + PublicInbox::DS::add_timer(0, \&imap_fetch_fork, + [$self, $intvl, $uris]); } } -- cgit v1.2.3-24-ge0c7