Class FutureComposer<T>

java.lang.Object
org.drasyl.util.FutureComposer<T>
Type Parameters:
T - result type of the current step's Future

public final class FutureComposer<T> extends Object
This utility class lat you chain up Futures.

A common need is to execute two or more asynchronous operations back to back, where each subsequent operation starts when the previous operation succeeds, with the result from the previous step.

  • Method Details

    • finish

      public io.netty.util.concurrent.Future<T> finish(io.netty.util.concurrent.EventExecutor executor)
      Binds all Futures in this FutureComposer to executor. Returns Future that completes if all previous Futures in this FutureComposer have been completed.
      Parameters:
      executor - EventExecutor to bind all Futures in this FutureComposer to
      Returns:
      Future that completes if all previous Futures in this FutureComposer have been completed
    • then

      public <R> FutureComposer<R> then(io.netty.util.concurrent.Future<R> future)
      Returns a new FutureComposer that will complete if all previous Futures and future have been completed.
    • then

      public <R> FutureComposer<R> then(Function<io.netty.util.concurrent.Future<T>,FutureComposer<R>> mapper)
      Returns a new FutureComposer that will complete if all previous Futures and the FutureComposer returned by mapper have been completed. Future will be passed to mapper.
    • then

      public <R> FutureComposer<R> then(Supplier<FutureComposer<R>> mapper)
    • composeFuture

      public static <R> FutureComposer<R> composeFuture(io.netty.util.concurrent.Future<R> future)
      Creates a new FutureComposer whose first Future is future.
      Type Parameters:
      R - type of future
      Parameters:
      future - the initial Future
      Returns:
      new FutureComposer whose first Future is future
    • composeSucceededFuture

      public static <R> FutureComposer<R> composeSucceededFuture(R result)
      Creates a new FutureComposer whose first Future was successfully completed with result.
      Type Parameters:
      R - type of result
      Parameters:
      result - result of the initial Future
      Returns:
      new FutureComposer whose first Future was successfully completed with result
    • composeSucceededFuture

      public static FutureComposer<Void> composeSucceededFuture()
      Creates a new FutureComposer whose first Future was successfully completed with null.
      Returns:
      new FutureComposer whose first Future was successfully completed with null
    • composeFailedFuture

      public static <R> FutureComposer<R> composeFailedFuture(Throwable cause)
      Creates a new FutureComposer whose first Future was failed with cause.
      Type Parameters:
      R - type of Future
      Parameters:
      cause - cause that failed the Future
      Returns:
      new FutureComposer whose first Future was failed with cause