Skip to content

Commit

Permalink
Hotfix issue #1606.
Browse files Browse the repository at this point in the history
Signed-off-by: Nikita Lebedev <[email protected]>
  • Loading branch information
thenswan committed Sep 18, 2023
1 parent d7096b3 commit 6c886e4
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion sdk/src/main/java/com/hedera/hashgraph/sdk/Delayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
package com.hedera.hashgraph.sdk;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.time.Duration;
Expand All @@ -33,6 +35,12 @@
final class Delayer {
private static final Logger logger = LoggerFactory.getLogger(Delayer.class);

private static final ScheduledExecutorService SCHEDULER = Executors.newSingleThreadScheduledExecutor(r -> {
Thread t = new Thread(r);
t.setDaemon(true);
return t;
});

private static final Duration MIN_DELAY = Duration.ofMillis(500);

/**
Expand Down Expand Up @@ -67,6 +75,10 @@ static CompletableFuture<Void> delayFor(long milliseconds, Executor executor) {
return CompletableFuture.runAsync(
() -> {
},
CompletableFuture.delayedExecutor(milliseconds, TimeUnit.MILLISECONDS, executor));
delayedExecutor(milliseconds, TimeUnit.MILLISECONDS, executor));
}

private static Executor delayedExecutor(long delay, TimeUnit unit, Executor executor) {
return r -> SCHEDULER.schedule(() -> executor.execute(r), delay, unit);
}
}

0 comments on commit 6c886e4

Please sign in to comment.