@@ -82,25 +82,22 @@ public void watch(Path root, @NonNull Consumer<Set<Path>> onChange, int delay) {
8282 }
8383 }
8484 key .reset ();
85- if (!modifiedFiles .isEmpty ()) {
86- delayNextChange (pendingFiles , modifiedFiles , notifyOnChangeTask , executorService , onChange , delay );
85+ if (!modifiedFiles .isEmpty () && pendingFiles . addAll ( modifiedFiles ) ) {
86+ delayNextChange (pendingFiles , notifyOnChangeTask , executorService , onChange , delay );
8787 }
8888 }
8989 Thread .currentThread ().interrupt ();
9090 }
9191 }
9292
93- private static void delayNextChange (Set <Path > pendingFiles , Set <Path > modifiedFiles ,
94- AtomicReference <ScheduledFuture <?>> notifyOnChangeTask ,
95- ScheduledExecutorService executorService ,
96- Consumer <Set <Path >> onChange , int delay ) {
97- pendingFiles .addAll (modifiedFiles );
93+ private static void delayNextChange (Set <Path > pendingFiles , AtomicReference <ScheduledFuture <?>> notifyOnChangeTask ,
94+ ScheduledExecutorService executorService , Consumer <Set <Path >> onChange , int delay ) {
9895 Optional .ofNullable (notifyOnChangeTask .getAndSet (executorService .schedule (() -> {
9996 Set <Path > toNotify = Set .copyOf (pendingFiles );
10097 pendingFiles .clear ();
10198 onChange .accept (toNotify );
10299 }, delay , TimeUnit .MILLISECONDS )))
103- .ifPresent (f -> f .cancel (false ));
100+ .ifPresent (task -> task .cancel (false ));
104101 }
105102
106103 @ SneakyThrows (IOException .class )
0 commit comments