@Beta @GwtCompatible(emulated=true) public abstract class FluentFuture<V> extends AbstractFuture<V>
ListenableFuture that supports fluent chains of operations. For example:
ListenableFuture<Boolean> adminIsLoggedIn =
FluentFuture.from(usersDatabase.getAdminUser())
.transform(User::getId, directExecutor())
.transform(ActivityService::isLoggedIn, threadPool)
.catching(RpcException.class, e -> false, directExecutor());
When chaining together a graph of asynchronous operations, 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:
CompletableFuture / CompletionStage
Users of CompletableFuture will likely want to continue using CompletableFuture. FluentFuture is targeted at people who use ListenableFuture,
who can't use Java 8, or who want an API more focused than CompletableFuture. (If you
need to adapt between CompletableFuture and ListenableFuture, consider Future Converter.)
FluentFuture but with extra methods, we recommend declaring your
own subclass of ListenableFuture, complete with a method like from(org.docx4j.com.google.common.util.concurrent.FluentFuture<V>) to adapt an
existing ListenableFuture, implemented atop a ForwardingListenableFuture that
forwards to that future and adds the desired methods.| Modifier and Type | Method and Description |
|---|---|
static <V> FluentFuture<V> |
from(FluentFuture<V> future)
Deprecated.
no need to use this
|
FluentFuture<V> |
withTimeout(long timeout,
TimeUnit unit,
ScheduledExecutorService scheduledExecutor)
Returns a future that delegates to this future but will finish early (via a
TimeoutException wrapped in an ExecutionException) if the specified timeout expires. |
addListener, afterDone, cancel, get, get, interruptTask, isCancelled, isDone, pendingToString, set, setException, setFuture, toString, tryInternalFastPathGetFailure, wasInterrupted@Deprecated public static <V> FluentFuture<V> from(FluentFuture<V> future)
@GwtIncompatible public final FluentFuture<V> withTimeout(long timeout, TimeUnit unit, ScheduledExecutorService scheduledExecutor)
TimeoutException wrapped in an ExecutionException) if the specified timeout expires.
If the timeout expires, not only will the output future finish, but also the input future
(this) will be cancelled and interrupted.timeout - when to time out the futureunit - the time unit of the time parameterscheduledExecutor - The executor service to enforce the timeout.Copyright © 2007-2020. All Rights Reserved.