Class Futures
- java.lang.Object
-
- com.github.mizool.core.concurrent.Futures
-
public final class Futures extends Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <V> Vget(@NonNull Future<V> future)Waits if necessary for the computation to complete, and then retrieves its result.static <V> Vget(@NonNull Future<V> future, @NonNull Duration duration)Waits if necessary for at most the given time for the computation to complete, and then retrieves its result, if available.static com.google.common.util.concurrent.ListenableFuture<Void>toVoidResult(@NonNull com.google.common.util.concurrent.ListenableFuture<?> future)Transforms anyListenableFutureinto aListenableFuturewithout result.static CompletableFuture<Void>toVoidResult(@NonNull CompletableFuture<?> future)Transforms anyCompletableFutureinto aCompletableFuturewithout result.
-
-
-
Method Detail
-
get
public static <V> V get(@NonNull @NonNull Future<V> future)Waits if necessary for the computation to complete, and then retrieves its result.- Returns:
- the computed result
- Throws:
com.google.common.util.concurrent.UncheckedExecutionException- if the computation threw an exceptionCancellationException- if the computation was cancelledUncheckedInterruptedException- if the thread was interrupted while waiting. Note: as required, the thread will be re-interrupted before throwing the exception.NullPointerException- iffutureisnull
-
get
public static <V> V get(@NonNull @NonNull Future<V> future, @NonNull @NonNull Duration duration)Waits if necessary for at most the given time for the computation to complete, and then retrieves its result, if available.- Returns:
- the computed result
- Throws:
com.google.common.util.concurrent.UncheckedTimeoutException- if the computation timed outcom.google.common.util.concurrent.UncheckedExecutionException- if the computation threw an exceptionCancellationException- if the computation was cancelledUncheckedInterruptedException- if the thread was interrupted while waiting. Note: as required, the thread will be re-interrupted before throwing the exception.NullPointerException- iffutureordurationisnull
-
toVoidResult
public static com.google.common.util.concurrent.ListenableFuture<Void> toVoidResult(@NonNull @NonNull com.google.common.util.concurrent.ListenableFuture<?> future)
Transforms anyListenableFutureinto aListenableFuturewithout result. Exceptions that are thrown by the original future are handled transparently.
The returned future does not contain a reference to the original future. That allows to reduce the overall memory footprint when working with multiple futures at once without caring for the results.- Parameters:
future- the future to wrap- Returns:
- a void future
- Throws:
NullPointerException- iffutureisnull
-
toVoidResult
public static CompletableFuture<Void> toVoidResult(@NonNull @NonNull CompletableFuture<?> future)
Transforms anyCompletableFutureinto aCompletableFuturewithout result. Exceptions that are thrown by the original future are handled transparently.
The returned future does not contain a reference to the original future. That allows to reduce the overall memory footprint when working with multiple futures at once without caring for the results.- Parameters:
future- the future to wrap- Returns:
- a void future
- Throws:
NullPointerException- iffutureisnull
-
-