Skip to content

Commit 4fb69dc

Browse files
committed
Add ActiveWatch as event handler arg to Watcher
1 parent 9607285 commit 4fb69dc

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/main/java/engineering/swat/watch/Watcher.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.nio.file.Path;
3333
import java.util.concurrent.CompletableFuture;
3434
import java.util.concurrent.Executor;
35+
import java.util.function.BiConsumer;
3536
import java.util.function.Consumer;
3637

3738
import org.apache.logging.log4j.LogManager;
@@ -54,8 +55,8 @@ public class Watcher {
5455
private final Path path;
5556
private volatile Executor executor = CompletableFuture::runAsync;
5657

57-
private static final Consumer<WatchEvent> EMPTY_HANDLER = p -> {};
58-
private volatile Consumer<WatchEvent> eventHandler = EMPTY_HANDLER;
58+
private static final BiConsumer<ActiveWatch, WatchEvent> EMPTY_HANDLER = (w, e) -> {};
59+
private volatile BiConsumer<ActiveWatch, WatchEvent> eventHandler = EMPTY_HANDLER;
5960

6061

6162
private Watcher(WatchScope scope, Path path) {
@@ -103,7 +104,7 @@ public Watcher on(Consumer<WatchEvent> eventHandler) {
103104
if (this.eventHandler != EMPTY_HANDLER) {
104105
throw new IllegalArgumentException("on handler cannot be set more than once");
105106
}
106-
this.eventHandler = eventHandler;
107+
this.eventHandler = (w, e) -> eventHandler.accept(e);
107108
return this;
108109
}
109110

@@ -114,7 +115,7 @@ public Watcher on(WatchEventListener listener) {
114115
if (this.eventHandler != EMPTY_HANDLER) {
115116
throw new IllegalArgumentException("on handler cannot be set more than once");
116117
}
117-
this.eventHandler = ev -> {
118+
this.eventHandler = (w, ev) -> {
118119
switch (ev.getKind()) {
119120
case CREATED:
120121
listener.onCreated(ev);

0 commit comments

Comments
 (0)