Skip to content

Commit

Permalink
cleaning up how the watch is stopped
Browse files Browse the repository at this point in the history
  • Loading branch information
shawkins committed Sep 7, 2022
1 parent 9686f6b commit 64905e1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
Expand Up @@ -164,7 +164,7 @@ public CompletableFuture<Void> start() {
return reflector.start().whenComplete((v, t) -> {
// stop called while run is called could be ineffective, check for it afterwards
synchronized (this) {
if (stopped) {
if (stopped && reflector.isRunning()) {
stop();
}
}
Expand Down
Expand Up @@ -29,10 +29,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CancellationException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.concurrent.ConcurrentSkipListSet;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -76,18 +75,15 @@ public void stop() {
}

private synchronized void stopWatcher() {
if (watchFuture != null) {
watchFuture.cancel(true);
try {
Watch w = watchFuture.getNow(null);
Optional.ofNullable(watchFuture).ifPresent(theFuture -> {
watchFuture = null;
theFuture.cancel(true);
theFuture.whenComplete((w, t) -> {
if (w != null) {
stopWatch(w);
}
} catch (CompletionException | CancellationException e) {
// do nothing
}
watchFuture = null;
}
});
});
}

/**
Expand Down

0 comments on commit 64905e1

Please sign in to comment.