Future interface.
Many of these methods use the ListenableFuture API; consult the Guava User Guide
article on ListenableFuture.
The main purpose of ListenableFuture is to help you chain together a graph of
asynchronous operations. You can chain them together manually with calls to methods like Futures., but you will often
find it easier to use a framework. Frameworks automate the process, often adding features like
monitoring, debugging, and cancellation. Examples of frameworks include:
If you do chain your operations manually, you may want to use FluentFuture.
| Modifier and Type | Class and Description |
|---|---|
| private static class | Futures.
See |
| public static class | Futures.
A helper to create a new |
| private static class | |
| private static class | |
| private static class | Futures.
A wrapped future that does not propagate cancellation to its delegate. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static <V extends @Nullable Object> void | addCallback(final ListenableFuture<V>
The future attach the callback to. future, final FutureCallback<? super V> The callback to invoke when callback, Executor future is completed.The executor to run executor)callback when the future completes.Registers separate success and failure callbacks to be run when the |
| public static <V extends @Nullable Object> ListenableFuture | Returns: a future that provides a list of the results of the component futuresfutures to combine futures)Creates a new |
| public static <V extends @Nullable Object> ListenableFuture | Returns: a future that provides a list of the results of the component futuresfutures to combine futures)Creates a new |
| public static <V extends @Nullable Object, X extends Throwable> ListenableFuture | catching(ListenableFuture<? extends V>
the primary input input, Class<X> Futurethe exception type that triggers use of exceptionType, Function<? super X, ? extends V> fallback. The exception
type is matched against the input's exception. "The input's exception" means the cause of
the ExecutionException thrown by input.get() or, if get() throws a
different kind of exception, that exception itself. To avoid hiding bugs and other
unrecoverable errors, callers should prefer more specific types, avoiding Throwable.class in particular.the fallback, Executor Function to be called if input fails with the expected
exception type. The function's argument is the input's exception. "The input's exception"
means the cause of the ExecutionException thrown by input.get() or, if
get() throws a different kind of exception, that exception itself.the executor that runs executor)fallback if input failsReturns a |
| public static <V extends @Nullable Object, X extends Throwable> ListenableFuture | catchingAsync(ListenableFuture<? extends V>
the primary input input, Class<X> Futurethe exception type that triggers use of exceptionType, AsyncFunction<? super X, ? extends V> fallback. The exception
type is matched against the input's exception. "The input's exception" means the cause of
the ExecutionException thrown by input.get() or, if get() throws a
different kind of exception, that exception itself. To avoid hiding bugs and other
unrecoverable errors, callers should prefer more specific types, avoiding Throwable.class in particular.the fallback, Executor AsyncFunction to be called if input fails with the expected
exception type. The function's argument is the input's exception. "The input's exception"
means the cause of the ExecutionException thrown by input.get() or, if
get() throws a different kind of exception, that exception itself.the executor that runs executor)fallback if input failsReturns a |
| public static <V extends @Nullable Object, X extends Exception> V | getChecked(Future<V> future, Class<X> exceptionClass)
Returns the result of |
| public static <V extends @Nullable Object, X extends Exception> V | getChecked(Future<V> future, Class<X> exceptionClass, Duration timeout)
Returns the result of |
| public static <V extends @Nullable Object, X extends Exception> V | getChecked(Future<V> future, Class<X> exceptionClass, long timeout, TimeUnit unit)
Returns the result of |
| public static <V extends @Nullable Object> V | |
| public static <V extends @Nullable Object> V | getUnchecked(Future<V> future)
Returns the result of calling |
| private static <T extends @Nullable Object> ListenableFuture | gwtCompatibleToArray(Iterable<? extends ListenableFuture<? extends T>> futures)
Can't use Iterables.toArray because it's not gwt compatible |
| public static <V extends @Nullable Object> ListenableFuture | immediateCancelledFuture()
Creates a |
| public static <V extends @Nullable Object> ListenableFuture | immediateFailedFuture(Throwable throwable)
Returns a |
| public static <V extends @Nullable Object> ListenableFuture | immediateFuture(V value)
Creates a |
| public static ListenableFuture | |
| public static <T extends @Nullable Object> ImmutableList | inCompletionOrder(Iterable<? extends ListenableFuture<? extends T>> futures)
Returns a list of delegate futures that correspond to the futures received in the order that they complete. |
| public static <I extends @Nullable Object, O extends @Nullable Object> Future | Returns: A future that returns the result of the transformation.The future to transform input, final Function<? super I, ? extends O> A Function to transform the results of the provided future to the results of
the returned future. function)Like |
| public static <V extends @Nullable Object> ListenableFuture | nonCancellationPropagating(ListenableFuture<V> future)
Returns a |
| public static <O extends @Nullable Object> ListenableFuture | scheduleAsync(AsyncCallable<O> callable, Duration delay, ScheduledExecutorService executorService)
Schedules |
| public static <O extends @Nullable Object> ListenableFuture | scheduleAsync(AsyncCallable<O> callable, long delay, TimeUnit timeUnit, ScheduledExecutorService executorService)
Schedules |
| public static <O extends @Nullable Object> ListenableFuture | |
| public static ListenableFuture | |
| public static <O extends @Nullable Object> ListenableFuture | submitAsync(AsyncCallable<O> callable, Executor executor)
Executes |
| public static <V extends @Nullable Object> ListenableFuture | Returns: a future that provides a list of the results of the component futuresfutures to combine futures)Creates a new |
| public static <V extends @Nullable Object> ListenableFuture | Returns: a future that provides a list of the results of the component futuresfutures to combine futures)Creates a new |
| public static <I extends @Nullable Object, O extends @Nullable Object> ListenableFuture | Returns: A future that holds result of the transformation.The future to transform input, Function<? super I, ? extends O> A Function to transform the results of the provided future to the results of
the returned future. function, Executor Executor to run the function in. executor)Returns a new |
| public static <I extends @Nullable Object, O extends @Nullable Object> ListenableFuture | Returns: A future that holds result of the function (if the input succeeded) or the original input's failure (if not)The future to transform input, AsyncFunction<? super I, ? extends O> A function to transform the result of the input future to the result of the
output future function, Executor Executor to run the function in. executor)Returns a new |
| public static <V extends @Nullable Object> Futures. | whenAllComplete(ListenableFuture<? extends V>... futures)
Creates a |
| public static <V extends @Nullable Object> Futures. | whenAllComplete(Iterable<? extends ListenableFuture<? extends V>> futures)
Creates a |
| public static <V extends @Nullable Object> Futures. | whenAllSucceed(ListenableFuture<? extends V>... futures)
Creates a |
| public static <V extends @Nullable Object> Futures. | whenAllSucceed(Iterable<? extends ListenableFuture<? extends V>> futures)
Creates a |
| public static <V extends @Nullable Object> ListenableFuture | withTimeout(ListenableFuture<V>
The future to delegate to. delegate, Duration when to time out the future time, ScheduledExecutorService The executor service to enforce the timeout. scheduledExecutor)Returns a future that delegates to another but will finish early (via a |
| public static <V extends @Nullable Object> ListenableFuture | withTimeout(ListenableFuture<V>
The future to delegate to. delegate, long when to time out the future time, TimeUnit the time unit of the time parameter unit, ScheduledExecutorService The executor service to enforce the timeout. scheduledExecutor)Returns a future that delegates to another but will finish early (via a |
| private static void |