Class Futures
java.lang.Object
com.github.mizool.core.concurrent.Futures
-
Method Summary
Modifier and TypeMethodDescriptionstatic <V> VWaits if necessary for the computation to complete, and then retrieves its result.static <V> VWaits 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 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- iffutureisnull
-
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- 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
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
-