diff options
author | dakkar <dakkar@thenautilus.net> | 2023-11-06 13:55:45 +0000 |
---|---|---|
committer | dakkar <dakkar@thenautilus.net> | 2023-11-06 13:55:45 +0000 |
commit | ea6c15c93c96569767cecdf7325a88b02b7faf6d (patch) | |
tree | 80d0bc3bac393a89d4f757c2f41141aca5987026 /lib/ScanDir.rakumod | |
parent | remove bad bit of openrc (diff) | |
download | media-control-ea6c15c93c96569767cecdf7325a88b02b7faf6d.tar.gz media-control-ea6c15c93c96569767cecdf7325a88b02b7faf6d.tar.bz2 media-control-ea6c15c93c96569767cecdf7325a88b02b7faf6d.zip |
quite the ScanDir supply when files are being modified
Diffstat (limited to 'lib/ScanDir.rakumod')
-rw-r--r-- | lib/ScanDir.rakumod | 12 |
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, + ); } |