Class Futures
java.lang.Object
com.github.mizool.core.concurrent.Futures
-
Method Summary
Modifier and TypeMethodDescriptionstatic <V> V
Waits if necessary for the computation to complete, and then retrieves its result.static <V> V
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 anyListenableFuture
into aListenableFuture
without result.static CompletableFuture<Void>
toVoidResult
(@NonNull CompletableFuture<?> future) Transforms anyCompletableFuture
into aCompletableFuture
without result.
-
Method Details
-
get
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
- iffuture
isnull
-
get
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
- iffuture
orduration
isnull
-
toVoidResult
public static com.google.common.util.concurrent.ListenableFuture<Void> toVoidResult(@NonNull @NonNull com.google.common.util.concurrent.ListenableFuture<?> future) Transforms anyListenableFuture
into aListenableFuture
without 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
- iffuture
isnull
-
toVoidResult
Transforms anyCompletableFuture
into aCompletableFuture
without 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
- iffuture
isnull
-