Class CompositeFutureImpl

java.lang.Object
dev.webfx.platform.async.impl.FutureImpl<CompositeFuture>
dev.webfx.platform.async.impl.CompositeFutureImpl
All Implemented Interfaces:
AsyncResult<CompositeFuture>, CompositeFuture, Future<CompositeFuture>, FutureInternal<CompositeFuture>, Listener<Object>

public class CompositeFutureImpl extends FutureImpl<CompositeFuture> implements CompositeFuture, Listener<Object>
Author:
Julien Viet
  • Method Details

    • all

      public static CompositeFuture all(Future<?>... results)
    • any

      public static CompositeFuture any(Future<?>... results)
    • join

      public static CompositeFuture join(Future<?>... results)
    • onSuccess

      public void onSuccess(Object value)
      Description copied from interface: Listener
      Signal the success.
      Specified by:
      onSuccess in interface Listener<Object>
      Parameters:
      value - the value
    • onFailure

      public void onFailure(Throwable failure)
      Description copied from interface: Listener
      Signal the failure
      Specified by:
      onFailure in interface Listener<Object>
      Parameters:
      failure - the failure
    • cause

      public Throwable cause(int index)
      Description copied from interface: CompositeFuture
      Returns a cause of a wrapped future
      Specified by:
      cause in interface CompositeFuture
      Parameters:
      index - the wrapped future index
    • succeeded

      public boolean succeeded(int index)
      Description copied from interface: CompositeFuture
      Returns true if a wrapped future is succeeded
      Specified by:
      succeeded in interface CompositeFuture
      Parameters:
      index - the wrapped future index
    • failed

      public boolean failed(int index)
      Description copied from interface: CompositeFuture
      Returns true if a wrapped future is failed
      Specified by:
      failed in interface CompositeFuture
      Parameters:
      index - the wrapped future index
    • isComplete

      public boolean isComplete(int index)
      Description copied from interface: CompositeFuture
      Returns true if a wrapped future is completed
      Specified by:
      isComplete in interface CompositeFuture
      Parameters:
      index - the wrapped future index
    • resultAt

      public <T> T resultAt(int index)
      Description copied from interface: CompositeFuture
      Returns the result of a wrapped future
      Specified by:
      resultAt in interface CompositeFuture
      Parameters:
      index - the wrapped future index
    • size

      public int size()
      Specified by:
      size in interface CompositeFuture
      Returns:
      the number of wrapped future
    • onComplete

      public CompositeFuture onComplete(Handler<AsyncResult<CompositeFuture>> handler)
      Description copied from interface: Future
      Add a handler to be notified of the result.

      WARNING: this is a terminal operation. If several handlers are registered, there is no guarantee that they will be invoked in order of registration.

      Specified by:
      onComplete in interface CompositeFuture
      Specified by:
      onComplete in interface Future<CompositeFuture>
      Overrides:
      onComplete in class FutureImpl<CompositeFuture>
      Parameters:
      handler - the handler that will be called with the result
      Returns:
      a reference to this, so it can be used fluently
    • onSuccess

      public CompositeFuture onSuccess(Handler<CompositeFuture> handler)
      Description copied from interface: Future
      Add a handler to be notified of the succeeded result.

      WARNING: this is a terminal operation. If several handlers are registered, there is no guarantee that they will be invoked in order of registration.

      Specified by:
      onSuccess in interface CompositeFuture
      Specified by:
      onSuccess in interface Future<CompositeFuture>
      Overrides:
      onSuccess in class FutureImpl<CompositeFuture>
      Parameters:
      handler - the handler that will be called with the succeeded result
      Returns:
      a reference to this, so it can be used fluently
    • onFailure

      public CompositeFuture onFailure(Handler<Throwable> handler)
      Description copied from interface: Future
      Add a handler to be notified of the failed result.

      WARNING: this is a terminal operation. If several handlers are registered, there is no guarantee that they will be invoked in order of registration.

      Specified by:
      onFailure in interface CompositeFuture
      Specified by:
      onFailure in interface Future<CompositeFuture>
      Overrides:
      onFailure in class FutureImpl<CompositeFuture>
      Parameters:
      handler - the handler that will be called with the failed result
      Returns:
      a reference to this, so it can be used fluently
    • formatValue

      protected void formatValue(Object value, StringBuilder sb)
      Overrides:
      formatValue in class FutureImpl<CompositeFuture>
    • emitSuccess

      protected final void emitSuccess(CompositeFuture value, Listener<CompositeFuture> listener)
      Create a future that hasn't completed yet
    • emitFailure

      protected final void emitFailure(Throwable cause, Listener<CompositeFuture> listener)
    • compose

      public <U> Future<U> compose(Function<CompositeFuture,Future<U>> successMapper, Function<Throwable,Future<U>> failureMapper)
      Description copied from interface: Future
      Compose this future with a successMapper and failureMapper functions.

      When this future (the one on which compose is called) succeeds, the successMapper will be called with the completed value and this mapper returns another future object. This returned future completion will complete the future returned by this method call.

      When this future (the one on which compose is called) fails, the failureMapper will be called with the failure and this mapper returns another future object. This returned future completion will complete the future returned by this method call.

      If any mapper function throws an exception, the returned future will be failed with this exception.

      Specified by:
      compose in interface Future<T>
      Parameters:
      successMapper - the function mapping the success
      failureMapper - the function mapping the failure
      Returns:
      the composed future
    • transform

      public <U> Future<U> transform(Function<AsyncResult<CompositeFuture>,Future<U>> mapper)
      Description copied from interface: Future
      Transform this future with a mapper functions.

      When this future (the one on which transform is called) completes, the mapper will be called with the async result and this mapper returns another future object. This returned future completion will complete the future returned by this method call.

      If any mapper function throws an exception, the returned future will be failed with this exception.

      Specified by:
      transform in interface Future<T>
      Parameters:
      mapper - the function mapping the future
      Returns:
      the transformed future
    • eventually

      public <U> Future<CompositeFuture> eventually(Function<Void,Future<U>> mapper)
      Description copied from interface: Future
      Compose this future with a function that will be always be called.

      When this future (the one on which eventually is called) completes, the function will be called and this mapper returns another future object. This returned future completion will complete the future returned by this method call with the original result of the future.

      The outcome of the future returned by the function will not influence the nature of the returned future.

      Specified by:
      eventually in interface Future<T>
      Parameters:
      mapper - the function returning the future.
      Returns:
      the composed future
    • map

      public <U> Future<U> map(Function<CompositeFuture,U> mapper)
      Description copied from interface: Future
      Apply a mapper function on this future.

      When this future succeeds, the mapper will be called with the completed value and this mapper returns a value. This value will complete the future returned by this method call.

      If the mapper throws an exception, the returned future will be failed with this exception.

      When this future fails, the failure will be propagated to the returned future and the mapper will not be called.

      Specified by:
      map in interface AsyncResult<T>
      Specified by:
      map in interface Future<T>
      Parameters:
      mapper - the mapper function
      Returns:
      the mapped future
    • map

      public <V> Future<V> map(V value)
      Description copied from interface: Future
      Map the result of a future to a specific value.

      When this future succeeds, this value will complete the future returned by this method call.

      When this future fails, the failure will be propagated to the returned future.

      Specified by:
      map in interface AsyncResult<T>
      Specified by:
      map in interface Future<T>
      Parameters:
      value - the value that eventually completes the mapped future
      Returns:
      the mapped future
    • otherwise

      Description copied from interface: Future
      Apply a mapper function on this future.

      When this future fails, the mapper will be called with the completed value and this mapper returns a value. This value will complete the future returned by this method call.

      If the mapper throws an exception, the returned future will be failed with this exception.

      When this future succeeds, the result will be propagated to the returned future and the mapper will not be called.

      Specified by:
      otherwise in interface AsyncResult<T>
      Specified by:
      otherwise in interface Future<T>
      Parameters:
      mapper - the mapper function
      Returns:
      the mapped future
    • otherwise

      public Future<CompositeFuture> otherwise(CompositeFuture value)
      Description copied from interface: Future
      Map the failure of a future to a specific value.

      When this future fails, this value will complete the future returned by this method call.

      When this future succeeds, the result will be propagated to the returned future.

      Specified by:
      otherwise in interface AsyncResult<T>
      Specified by:
      otherwise in interface Future<T>
      Parameters:
      value - the value that eventually completes the mapped future
      Returns:
      the mapped future