Interface Promise<C>

Type Parameters:
C - the type of the context object
All Known Implementing Classes:
AbstractConnectionPool.FutureConnection, FuturePromise, HttpProxy.CreateTunnelPromise, HttpProxy.TunnelPromise, Promise.Adapter, Promise.Completable, Promise.Wrapper

public interface Promise<C>

A callback abstraction that handles completed/failed events of asynchronous operations.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static class 
    Empty implementation of Promise.
    static class 
    A CompletableFuture that is also a Promise.
    static class 
     
  • Method Summary

    Modifier and Type
    Method
    Description
    default void
    Callback invoked when the operation fails.
    static <T> Promise<T>
    from(CompletableFuture<? super T> completable)
    Creates a promise from the given incomplete CompletableFuture.
    default void
    succeeded(C result)
    Callback invoked when the operation completes.
  • Method Details

    • succeeded

      default void succeeded(C result)

      Callback invoked when the operation completes.

      Parameters:
      result - the context
      See Also:
    • failed

      default void failed(Throwable x)

      Callback invoked when the operation fails.

      Parameters:
      x - the reason for the operation failure
    • from

      static <T> Promise<T> from(CompletableFuture<? super T> completable)

      Creates a promise from the given incomplete CompletableFuture.

      When the promise completes, either succeeding or failing, the CompletableFuture is also completed, respectively via CompletableFuture.complete(Object) or CompletableFuture.completeExceptionally(Throwable).

      Type Parameters:
      T - the type of the result
      Parameters:
      completable - the CompletableFuture to convert into a promise
      Returns:
      a promise that when completed, completes the given CompletableFuture