com.arangodb.vst.internal.utils.CompletableFutureUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of vst-protocol Show documentation
Show all versions of vst-protocol Show documentation
VST Protocol module for ArangoDB Java Driver
package com.arangodb.vst.internal.utils;
import java.util.concurrent.*;
public class CompletableFutureUtils {
private CompletableFutureUtils() {
}
private static final ScheduledExecutorService timeoutScheduler = Executors.newSingleThreadScheduledExecutor(r -> {
Thread t = Executors.defaultThreadFactory().newThread(r);
t.setDaemon(true);
return t;
}
);
public static CompletableFuture orTimeout(CompletableFuture completableFuture, long timeout, TimeUnit unit) {
ScheduledFuture> timeoutTask = timeoutScheduler.schedule(() ->
completableFuture.completeExceptionally(new TimeoutException()), timeout, unit);
completableFuture.whenComplete((v, e) -> timeoutTask.cancel(false));
return completableFuture;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy