Class CompletableFutures
- java.lang.Object
-
- org.opendaylight.infrautils.utils.concurrent.CompletableFutures
-
public final class CompletableFutures extends Object
Utilities forCompletableFuture
.- Author:
- Michael Vorburger.ch
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> CompletableFuture<T>
completedExceptionally(Throwable throwable)
Return an immediately exceptional completed CompletableFuture.static <V> com.google.common.util.concurrent.ListenableFuture<V>
toListenableFuture(CompletableFuture<V> completableFuture)
Converts a Java 8 CompletionStage to a Guava ListenableFuture.
-
-
-
Method Detail
-
toListenableFuture
public static <V> com.google.common.util.concurrent.ListenableFuture<V> toListenableFuture(CompletableFuture<V> completableFuture)
Converts a Java 8 CompletionStage to a Guava ListenableFuture. SeeCompletionStages.toListenableFuture(CompletionStage)
for a related function.
-
completedExceptionally
public static <T> CompletableFuture<T> completedExceptionally(Throwable throwable)
Return an immediately exceptional completed CompletableFuture.Inspired by Guava's
Futures.immediateFailedFuture(Throwable)
.Useful because while CompletableFuture does have a
CompletableFuture.completedFuture(Object)
static factory method to obtain immediate non-exceptional value completion, it is missing a static factory method like this. This is often useful, e.g. when catching exceptions to transform into CompletableFuture to return, and saves the 3 lines to create a new instance, invoke the non-staticCompletableFuture.completeExceptionally(Throwable)
and return the completableFuture. (It's not possible to use chained invocation style, because completeExceptionally does not return this but a boolean, which is useless when requiring an immediately completed CompletionStage.)
-
-