public class MoreFutures extends Object
Modifier and Type | Method and Description |
---|---|
static <V> com.google.common.util.concurrent.ListenableFuture<Unit> |
addListenableCallback(com.google.common.util.concurrent.ListenableFuture<V> future,
com.google.common.util.concurrent.FutureCallback<? super V> callback,
Executor executor)
Add a callback to a listenable future
|
static <U,V> com.google.common.util.concurrent.ListenableFuture<Pair<U,V>> |
combinedFutures(com.google.common.util.concurrent.ListenableFuture<U> first,
com.google.common.util.concurrent.ListenableFuture<V> second,
com.google.common.util.concurrent.ListeningExecutorService executorService)
Combine the and listenable futures, returning a listenable
future that wraps the result of these futures as a
Pair . |
static <V> com.google.common.util.concurrent.FutureCallback<V> |
finallyCallback(java.util.function.Consumer<com.google.common.util.concurrent.ListenableFuture<V>> callable) |
static <V> com.google.common.util.concurrent.FutureCallback<V> |
finallyCallback(Runnable runnable) |
static <V> List<V> |
getAll(com.google.common.util.concurrent.ListeningExecutorService executorService,
Iterable<Callable<V>> callables)
Invoke multiple callables on the provided executor and wait for all to return successfully.
|
static Throwable |
getFailure(com.google.common.util.concurrent.ListenableFuture<?> future)
Returns the failure for a
ListenableFuture . |
static <V> V |
getUncheckedInterruptibly(Future<V> future)
Waits for the given future to complete and returns the result.
|
static boolean |
isSuccess(com.google.common.util.concurrent.ListenableFuture<?> future)
Create a convenience method for checking whether a future completed successfully because this
does not appear to be possible to do in a more direct way:
https://groups.google.com/forum/?fromgroups=#!topic/guava-discuss/rofEhagKnOc.
|
static <X extends Throwable> |
propagateCauseIfInstanceOf(Throwable e,
Class<X> type) |
public static <U,V> com.google.common.util.concurrent.ListenableFuture<Pair<U,V>> combinedFutures(com.google.common.util.concurrent.ListenableFuture<U> first, com.google.common.util.concurrent.ListenableFuture<V> second, com.google.common.util.concurrent.ListeningExecutorService executorService)
Pair
.public static <V> List<V> getAll(com.google.common.util.concurrent.ListeningExecutorService executorService, Iterable<Callable<V>> callables) throws ExecutionException, InterruptedException
executorService
- Executor service.callables
- Callables to call.ExecutionException
- If any callable throws an exception, the first of such is wrapped in
an ExecutionException and thrown. Access via Throwable.getCause()
}.InterruptedException
public static boolean isSuccess(com.google.common.util.concurrent.ListenableFuture<?> future) throws InterruptedException
InterruptedException
public static Throwable getFailure(com.google.common.util.concurrent.ListenableFuture<?> future) throws InterruptedException
ListenableFuture
.future
- Must have completed unsuccessfully.InterruptedException
public static <V> com.google.common.util.concurrent.ListenableFuture<Unit> addListenableCallback(com.google.common.util.concurrent.ListenableFuture<V> future, com.google.common.util.concurrent.FutureCallback<? super V> callback, Executor executor)
public static <V> V getUncheckedInterruptibly(Future<V> future)
CancellationException
. All exceptions thrown are wrapped with BuckUncheckedExecutionException
public static <X extends Throwable> void propagateCauseIfInstanceOf(Throwable e, Class<X> type)
public static <V> com.google.common.util.concurrent.FutureCallback<V> finallyCallback(Runnable runnable)
FutureCallback
which executes the given Runnable
on both success and
error.public static <V> com.google.common.util.concurrent.FutureCallback<V> finallyCallback(java.util.function.Consumer<com.google.common.util.concurrent.ListenableFuture<V>> callable)
FutureCallback
which executes the given Consumer
on both success and
error. This just makes it simpler to add unconditional callbacks.