Package org.drasyl.util
Class FutureUtil
java.lang.Object
org.drasyl.util.FutureUtil
Utility class for future-related operations.
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidcompleteOnAllOf(CompletableFuture<Void> future, Collection<CompletableFuture<?>> futures) Completesfutureif all of the givenfuturesare completed.static voidcompleteOnAllOf(CompletableFuture<Void> future, CompletableFuture<?>... futures) Completesfutureif all of the givenfuturesare completed.static voidcompleteOnAnyOfExceptionally(CompletableFuture<?> future, Collection<CompletableFuture<?>> futures) Completesfutureexceptionally if one of the givenfuturesare completed exceptionally.static voidcompleteOnAnyOfExceptionally(CompletableFuture<?> future, CompletableFuture<?>... futures) Completesfutureexceptionally if one of the givenfuturesare completed exceptionally.static CompletableFuture<Void>getCompleteOnAllOf(Collection<CompletableFuture<?>> futures) Returns a completed future if all of the givenfuturesare completed.static CompletableFuture<Void>getCompleteOnAllOf(CompletableFuture<?>... futures) Returns a completed future if all of the givenfuturesare completed.static <T> CompletableFuture<T>toFuture(io.netty.util.concurrent.Future<T> future) Translates the NettyFutureto aCompletableFuture.
-
Method Details
-
toFuture
Translates the NettyFutureto aCompletableFuture.- Type Parameters:
T- The result type of the future- Parameters:
future- The future to be translated- Returns:
- The translated
CompletableFuture
-
completeOnAnyOfExceptionally
public static void completeOnAnyOfExceptionally(CompletableFuture<?> future, Collection<CompletableFuture<?>> futures) Completesfutureexceptionally if one of the givenfuturesare completed exceptionally. If the given array offuturesis empty, nothing happens.- Parameters:
future- future that should be completedfutures- futures that should be waited for- Throws:
NullPointerException- iffutureorfuturesis null
-
completeOnAnyOfExceptionally
public static void completeOnAnyOfExceptionally(CompletableFuture<?> future, CompletableFuture<?>... futures) Completesfutureexceptionally if one of the givenfuturesare completed exceptionally. If the given array offuturesis empty, nothing happens.- Parameters:
future- future that should be completedfutures- futures that should be waited for- Throws:
NullPointerException- iffutureorfuturesis null
-
getCompleteOnAllOf
Returns a completed future if all of the givenfuturesare completed. When any of the givenfuturescompletes exceptionally, the future will also completes exceptionally immediately. If the given list offuturesis empty, the future is completed immediately.- Parameters:
futures- futures that should be waited for- Throws:
NullPointerException- iffuturesis null
-
getCompleteOnAllOf
Returns a completed future if all of the givenfuturesare completed. When any of the givenfuturescompletes exceptionally, the future will also completes exceptionally immediately. If the given array offuturesis empty, the future is completed immediately.- Parameters:
futures- futures that should be waited for- Throws:
NullPointerException- iffuturesis null
-
completeOnAllOf
public static void completeOnAllOf(CompletableFuture<Void> future, Collection<CompletableFuture<?>> futures) Completesfutureif all of the givenfuturesare completed. When any of the givenfuturescompletes exceptionally, the givenfuturewill also completes exceptionally immediately. If the given list offuturesis empty, thefutureis completed immediately.- Parameters:
future- future that should be completedfutures- futures that should be waited for- Throws:
NullPointerException- iffutureorfuturesis null
-
completeOnAllOf
Completesfutureif all of the givenfuturesare completed. When any of the givenfuturescompletes exceptionally, the givenfuturewill also completes exceptionally immediately. If the given array offuturesis empty, thefutureis completed immediately.- Parameters:
future- future that should be completedfutures- futures that should be waited for- Throws:
NullPointerException- iffutureorfuturesis null
-