diff options
author | Eric Wong <e@80x24.org> | 2021-09-18 09:33:27 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2021-09-18 20:25:28 +0000 |
commit | e693f102e230796a13a648750b65b8ca38f04a16 (patch) | |
tree | d69478c1b80714fa8bbfc36931429b1ca23858ef /lib/PublicInbox/LeiNoteEvent.pm | |
parent | 04bb05ee7f8d304757cbb016128c0aea157fc842 (diff) | |
download | public-inbox-e693f102e230796a13a648750b65b8ca38f04a16.tar.gz |
A common pattern we use is to arm a timer once and prevent it from being armed until it fires. We'll be using it more to do polling for saved searches and imports.
Diffstat (limited to 'lib/PublicInbox/LeiNoteEvent.pm')
-rw-r--r-- | lib/PublicInbox/LeiNoteEvent.pm | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/lib/PublicInbox/LeiNoteEvent.pm b/lib/PublicInbox/LeiNoteEvent.pm index c03c5319..18313359 100644 --- a/lib/PublicInbox/LeiNoteEvent.pm +++ b/lib/PublicInbox/LeiNoteEvent.pm @@ -7,8 +7,8 @@ package PublicInbox::LeiNoteEvent; use strict; use v5.10.1; use parent qw(PublicInbox::IPC); +use PublicInbox::DS; -my $flush_timer; our $to_flush; # { cfgpath => $lei } sub flush_lei ($) { @@ -20,7 +20,6 @@ sub flush_lei ($) { # we batch up writes and flush every 5s (matching Linux default # writeback behavior) since MUAs can trigger a storm of inotify events sub flush_task { # PublicInbox::DS timer callback - undef $flush_timer; my $todo = $to_flush // return; $to_flush = undef; for my $lei (values %$todo) { flush_lei($lei) } @@ -29,7 +28,7 @@ sub flush_task { # PublicInbox::DS timer callback # sets a timer to flush sub note_event_arm_done ($) { my ($lei) = @_; - $flush_timer //= PublicInbox::DS::add_timer(5, \&flush_task); + PublicInbox::DS::add_uniq_timer('flush_timer', 5, \&flush_task); $to_flush->{$lei->{cfg}->{'-f'}} //= $lei; } |