From e693f102e230796a13a648750b65b8ca38f04a16 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 18 Sep 2021 09:33:27 +0000 Subject: ds: support add unique timers 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. --- lib/PublicInbox/LeiNoteEvent.pm | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'lib/PublicInbox/LeiNoteEvent.pm') 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; } -- cgit v1.2.3-24-ge0c7