Class FluentFuture<V>

All Implemented Interfaces:
java.util.concurrent.Future<V>, ListenableFuture<V>

@Beta
@GwtCompatible(emulated=true)
public abstract class FluentFuture<V>
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(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.
Since:
23.0
  • Method Details

    • from

      @Deprecated public static <V> FluentFuture<V> from​(FluentFuture<V> future)
      Deprecated.
      no need to use this
      Simply returns its argument.
      Since:
      NEXT
    • withTimeout

      @GwtIncompatible public final FluentFuture<V> withTimeout​(long timeout, java.util.concurrent.TimeUnit unit, java.util.concurrent.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. If the timeout expires, not only will the output future finish, but also the input future (this) will be cancelled and interrupted.
      Parameters:
      timeout - when to time out the future
      unit - the time unit of the time parameter
      scheduledExecutor - The executor service to enforce the timeout.