Class FluentFuture<V extends @Nullable Object>

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

    @DoNotMock("Use FluentFuture.from(Futures.immediate*Future) or SettableFuture")
    @GwtCompatible(emulated=true)
    public abstract class FluentFuture<V extends @Nullable Object>
    extends AbstractFuture<V>
    A 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());
     

    Alternatives

    Frameworks

    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.)

    Extension

    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(com.google.common.util.concurrent.ListenableFuture<V>) to adapt an existing ListenableFuture, implemented atop a ForwardingListenableFuture that forwards to that future and adds the desired methods.
    Since:
    23.0