File tree Expand file tree Collapse file tree 1 file changed +8
-4
lines changed
src/main/java/ch/powerunit/extensions/async/impl Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -37,10 +37,7 @@ public FilePool(Path directory, WatchEvent.Kind<?>... events) {
3737
3838 @ Override
3939 public Collection <WatchEvent <Path >> call () throws Exception {
40- if (watcher == null ) {
41- watcher = directory .getFileSystem ().newWatchService ();
42- key = directory .register (watcher , events );
43- }
40+ initIfNeeded ();
4441 try {
4542 return key .pollEvents ().stream ().filter (IGNORE_OVERFLOW ).map (COERCE_TO_PATH )
4643 .collect (collectingAndThen (toList (), Collections ::unmodifiableList ));
@@ -53,6 +50,13 @@ public void close() {
5350 Optional .ofNullable (watcher ).ifPresent (FilePool ::safeCloseWatchService );
5451 }
5552
53+ private void initIfNeeded () throws IOException {
54+ if (watcher == null ) {
55+ watcher = directory .getFileSystem ().newWatchService ();
56+ key = directory .register (watcher , events );
57+ }
58+ }
59+
5660 private static void safeCloseWatchService (WatchService watcher ) {
5761 try {
5862 watcher .close ();
You can’t perform that action at this time.
0 commit comments