Package com.networknt.kafka.producer
Class CompletableFutures
- java.lang.Object
-
- com.networknt.kafka.producer.CompletableFutures
-
public final class CompletableFutures extends Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> CompletableFuture<List<T>>allAsList(List<CompletableFuture<T>> futures)Returns aCompletableFuturewhich will complete after allfutureshave completed, and when complete, will contain the value of allfutures.static <T,E extends Throwable>
CompletableFuture<T>catchingCompose(CompletableFuture<T> future, Class<E> exceptionClass, Function<? super E,? extends CompletableFuture<T>> handler)Returns a newCompletableFuturethat is completed whenfutureis complete, catching the givenexceptionClass.static <T> CompletableFuture<T>failedFuture(Throwable exception)Returns aCompletableFuturethat is completed exceptionally with the givenexception.
-
-
-
Method Detail
-
allAsList
public static <T> CompletableFuture<List<T>> allAsList(List<CompletableFuture<T>> futures)
Returns aCompletableFuturewhich will complete after allfutureshave completed, and when complete, will contain the value of allfutures.If any of the
futuresfail, the resultingCompletableFuturewill complete exceptionally with that future's failure.- Type Parameters:
T- paramter- Parameters:
futures- a list of futures- Returns:
- completableFuture of list
-
failedFuture
public static <T> CompletableFuture<T> failedFuture(Throwable exception)
Returns aCompletableFuturethat is completed exceptionally with the givenexception.- Type Parameters:
T- parameter- Parameters:
exception- Throwable- Returns:
- completableFuture
-
catchingCompose
public static <T,E extends Throwable> CompletableFuture<T> catchingCompose(CompletableFuture<T> future, Class<E> exceptionClass, Function<? super E,? extends CompletableFuture<T>> handler)
Returns a newCompletableFuturethat is completed whenfutureis complete, catching the givenexceptionClass.If
futurecompletes normally, then the returned future completes normally with the same value. Iffuturecompletes exceptionally with anexceptionClass, the returned future completes with the result of thehandler. Otherwise, the returned future will complete exceptionally with the same exception asfuture.- Type Parameters:
T- parameterE- parameter- Parameters:
future- the completable futureexceptionClass- exception classhandler- the function handler- Returns:
- T
-
-