java.lang.Object
org.neo4j.driver.internal.util.Futures
-
Method Summary
Modifier and TypeMethodDescriptionstatic CompletionExceptionasCompletionException(Throwable error) Helped method to turn given exception into aCompletionException.static <T> CompletionStage<T>asCompletionStage(io.netty.util.concurrent.Future<T> future) static <T> CompletionStage<T>asCompletionStage(io.netty.util.concurrent.Future<T> future, CompletableFuture<T> result) static <V> VblockingGet(CompletionStage<V> stage) static <V> VblockingGet(CompletionStage<V> stage, Runnable interruptHandler) static CompletionExceptioncombineErrors(Throwable error1, Throwable error2) Combine given errors into a singleCompletionExceptionto be rethrown from inside aCompletionStagechain.static <T> CompletableFuture<T>static <T> CompletableFuture<T>completeWithNullIfNoError(CompletableFuture<T> future, Throwable error) static ThrowableHelper method to extract cause of aCompletionException.static <T> CompletableFuture<T>failedFuture(Throwable error) static <T> BiConsumer<T,Throwable> futureCompletingConsumer(CompletableFuture<T> future) static <T> TgetNow(CompletionStage<T> stage) static <T> TjoinNowOrElseThrow(CompletableFuture<T> future, Supplier<? extends RuntimeException> exceptionSupplier) static <T> CompletableFuture<T>onErrorContinue(CompletableFuture<T> future, Throwable errorRecorder, Function<Throwable, ? extends CompletionStage<T>> onErrorAction) Given a future, if the future completes successfully then return a new completed future with the completed value.
-
Method Details
-
completedWithNull
-
completeWithNullIfNoError
public static <T> CompletableFuture<T> completeWithNullIfNoError(CompletableFuture<T> future, Throwable error) -
asCompletionStage
-
asCompletionStage
public static <T> CompletionStage<T> asCompletionStage(io.netty.util.concurrent.Future<T> future, CompletableFuture<T> result) -
failedFuture
-
blockingGet
-
blockingGet
-
getNow
-
joinNowOrElseThrow
public static <T> T joinNowOrElseThrow(CompletableFuture<T> future, Supplier<? extends RuntimeException> exceptionSupplier) -
completionExceptionCause
Helper method to extract cause of aCompletionException.When using
CompletionStage.whenComplete(BiConsumer)andCompletionStage.handle(BiFunction)propagated exceptions might get wrapped in aCompletionException.- Parameters:
error- the exception to get cause for.- Returns:
- cause of the given exception if it is a
CompletionException, given exception otherwise.
-
asCompletionException
Helped method to turn given exception into aCompletionException.- Parameters:
error- the exception to convert.- Returns:
- given exception wrapped with
CompletionExceptionif it's not one already.
-
combineErrors
Combine given errors into a singleCompletionExceptionto be rethrown from inside aCompletionStagechain.- Parameters:
error1- the first error ornull.error2- the second error ornull.- Returns:
nullif both errors are null,CompletionExceptionotherwise.
-
onErrorContinue
public static <T> CompletableFuture<T> onErrorContinue(CompletableFuture<T> future, Throwable errorRecorder, Function<Throwable, ? extends CompletionStage<T>> onErrorAction) Given a future, if the future completes successfully then return a new completed future with the completed value. Otherwise if the future completes with an error, then this method first saves the error in the error recorder, and then continues with the onErrorAction.- Type Parameters:
T- type- Parameters:
future- the future.errorRecorder- saves error if the given future completes with an error.onErrorAction- continues the future with this action if the future completes with an error.- Returns:
- a new completed future with the same completed value if the given future completes successfully, otherwise continues with the onErrorAction.
-
futureCompletingConsumer
-