Package org.drasyl.util
Class FutureUtil
- java.lang.Object
-
- org.drasyl.util.FutureUtil
-
public final class FutureUtil extends Object
Utility class for future-related operations.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
completeOnAllOf(CompletableFuture<Void> future, Collection<CompletableFuture<?>> futures)
Completesfuture
if all of the givenfutures
are completed.static void
completeOnAllOf(CompletableFuture<Void> future, CompletableFuture<?>... futures)
Completesfuture
if all of the givenfutures
are completed.static void
completeOnAnyOfExceptionally(CompletableFuture<?> future, Collection<CompletableFuture<?>> futures)
Completesfuture
exceptionally if one of the givenfutures
are completed exceptionally.static void
completeOnAnyOfExceptionally(CompletableFuture<?> future, CompletableFuture<?>... futures)
Completesfuture
exceptionally if one of the givenfutures
are completed exceptionally.static CompletableFuture<Void>
getCompleteOnAllOf(Collection<CompletableFuture<?>> futures)
Returns a completed future if all of the givenfutures
are completed.static CompletableFuture<Void>
getCompleteOnAllOf(CompletableFuture<?>... futures)
Returns a completed future if all of the givenfutures
are completed.static <T> CompletableFuture<T>
toFuture(io.netty.util.concurrent.Future<T> future)
Translates the NettyFuture
to aCompletableFuture
.
-
-
-
Method Detail
-
toFuture
public static <T> CompletableFuture<T> toFuture(io.netty.util.concurrent.Future<T> future)
Translates the NettyFuture
to 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)
Completesfuture
exceptionally if one of the givenfutures
are completed exceptionally. If the given array offutures
is empty, nothing happens.- Parameters:
future
- future that should be completedfutures
- futures that should be waited for- Throws:
NullPointerException
- iffuture
orfutures
is null
-
completeOnAnyOfExceptionally
public static void completeOnAnyOfExceptionally(CompletableFuture<?> future, CompletableFuture<?>... futures)
Completesfuture
exceptionally if one of the givenfutures
are completed exceptionally. If the given array offutures
is empty, nothing happens.- Parameters:
future
- future that should be completedfutures
- futures that should be waited for- Throws:
NullPointerException
- iffuture
orfutures
is null
-
getCompleteOnAllOf
public static CompletableFuture<Void> getCompleteOnAllOf(Collection<CompletableFuture<?>> futures)
Returns a completed future if all of the givenfutures
are completed. When any of the givenfutures
completes exceptionally, the future will also completes exceptionally immediately. If the given list offutures
is empty, the future is completed immediately.- Parameters:
futures
- futures that should be waited for- Throws:
NullPointerException
- iffutures
is null
-
getCompleteOnAllOf
public static CompletableFuture<Void> getCompleteOnAllOf(CompletableFuture<?>... futures)
Returns a completed future if all of the givenfutures
are completed. When any of the givenfutures
completes exceptionally, the future will also completes exceptionally immediately. If the given array offutures
is empty, the future is completed immediately.- Parameters:
futures
- futures that should be waited for- Throws:
NullPointerException
- iffutures
is null
-
completeOnAllOf
public static void completeOnAllOf(CompletableFuture<Void> future, Collection<CompletableFuture<?>> futures)
Completesfuture
if all of the givenfutures
are completed. When any of the givenfutures
completes exceptionally, the givenfuture
will also completes exceptionally immediately. If the given list offutures
is empty, thefuture
is completed immediately.- Parameters:
future
- future that should be completedfutures
- futures that should be waited for- Throws:
NullPointerException
- iffuture
orfutures
is null
-
completeOnAllOf
public static void completeOnAllOf(CompletableFuture<Void> future, CompletableFuture<?>... futures)
Completesfuture
if all of the givenfutures
are completed. When any of the givenfutures
completes exceptionally, the givenfuture
will also completes exceptionally immediately. If the given array offutures
is empty, thefuture
is completed immediately.- Parameters:
future
- future that should be completedfutures
- futures that should be waited for- Throws:
NullPointerException
- iffuture
orfutures
is null
-
-