aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/ScanDir.rakumod12
1 files 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,
+ );
}