Skip to content

Commit

Permalink
Fixed SonarCloud warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
javadev committed Oct 30, 2024
1 parent ad341d9 commit aa9dbb9
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/main/java/com/github/underscore/Underscore.java
Original file line number Diff line number Diff line change
Expand Up @@ -2098,13 +2098,14 @@ public static <T> java.util.concurrent.ScheduledFuture<T> delay(
final Supplier<T> function, final int delayMilliseconds) {
final java.util.concurrent.ScheduledExecutorService scheduler =
java.util.concurrent.Executors.newSingleThreadScheduledExecutor();
final java.util.concurrent.ScheduledFuture<T> future =
scheduler.schedule(
function::get,
delayMilliseconds,
java.util.concurrent.TimeUnit.MILLISECONDS);
scheduler.shutdown();
return future;
try {
return scheduler.schedule(
function::get,
delayMilliseconds,
java.util.concurrent.TimeUnit.MILLISECONDS);
} finally {
scheduler.shutdown();
}
}

public static <T> java.util.concurrent.ScheduledFuture<T> defer(final Supplier<T> function) {
Expand Down Expand Up @@ -3624,6 +3625,7 @@ public static <T> java.util.concurrent.ScheduledFuture setInterval(
final Supplier<T> function, final int delayMilliseconds) {
final java.util.concurrent.ScheduledExecutorService scheduler =
java.util.concurrent.Executors.newSingleThreadScheduledExecutor();
Runtime.getRuntime().addShutdownHook(new Thread(scheduler::shutdown));
return scheduler.scheduleAtFixedRate(
function::get,
delayMilliseconds,
Expand Down

0 comments on commit aa9dbb9

Please sign in to comment.