Class FluentFuture<V extends @Nullable Object>

  • All Implemented Interfaces:
    ListenableFuture<V>, Future<V>

    @DoNotMock("Use FluentFuture.from(Futures.immediate*Future) or SettableFuture")
    public abstract class FluentFuture<V extends @Nullable Object>
    extends AbstractFuture<V>
    A ListenableFuture that supports fluent chains of operations. For example:
     ListenableFuture<Boolean> adminIsLoggedIn =
             .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.)


    If you want a class like FluentFuture but with extra methods, we recommend declaring your own subclass of ListenableFuture, complete with a method like from(<V>) to adapt an existing ListenableFuture, implemented atop a ForwardingListenableFuture that forwards to that future and adds the desired methods.