From ea6c15c93c96569767cecdf7325a88b02b7faf6d Mon Sep 17 00:00:00 2001 From: dakkar Date: Mon, 6 Nov 2023 13:55:45 +0000 Subject: quite the ScanDir supply when files are being modified --- lib/ScanDir.rakumod | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/ScanDir.rakumod b/lib/ScanDir.rakumod index 34cb9e2..0f33a8b 100644 --- a/lib/ScanDir.rakumod +++ b/lib/ScanDir.rakumod @@ -4,7 +4,7 @@ unit module ScanDir; class End {}; sub scan-dir(*@paths --> Supply) is export { - supply { + my $s = supply { my %watched-dirs; CATCH { when X::IO { }; default { warn $_ } } @@ -46,5 +46,13 @@ sub scan-dir(*@paths --> Supply) is export { add-dir(@paths».IO); emit End; - } + }; + + # let's not return multiple events for the same path too quickly, + # otherwise the consumer will get overwhelmed when (for example) a + # large file is being written + return $s.unique( + with => sub { $^a !~~ End && $^b !~~ End && $^a eq $^b }, + expires => 0.1, + ); } -- cgit v1.2.3