Interface Promise<C>

Type Parameters:
C - the type of the context object
All Known Subinterfaces:
Blocker.Promise<C>, Promise.Invocable<R>
All Known Implementing Classes:
FuturePromise, HTTPSessionListenerPromise, Promise.Adapter, Promise.Completable, Promise.Task, Promise.Wrapper

public interface Promise<C>

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

  • Field Details

  • Method Details

    • noop

      static <T> Promise<T> noop()
    • 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
    • completeWith

      default void completeWith(CompletableFuture<C> completable)

      Completes this promise with the given CompletableFuture.

      When the CompletableFuture completes normally, this promise is succeeded; when the CompletableFuture completes exceptionally, this promise is failed.

      Parameters:
      completable - the CompletableFuture that completes this promise
    • from

      static <T> Promise<T> from(Consumer<T> success, Consumer<Throwable> failure)

      Creates a Promise from the given success and failure consumers.

      Type Parameters:
      T - the type of the result
      Parameters:
      success - the consumer invoked when the promise is succeeded
      failure - the consumer invoked when the promise is failed
      Returns:
      a new Promise wrapping the success and failure consumers.
    • 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
    • from

      static <C> Promise.Invocable<C> from(Invocable.InvocationType invocationType, Promise<C> promise)
      Type Parameters:
      C - The type
      Parameters:
      invocationType - The Invocable.InvocationType of calls to the Promise.Invocable
      promise - The promise on which to delegate calls to.
      Returns:
      An Invocable Promise.
    • from

      static <C> Promise.Invocable<C> from(Executor executor, Promise<C> promise)
      Create an Promise.Invocable that is Invocable.InvocationType.NON_BLOCKING because it executes the callbacks
      Type Parameters:
      C - The type
      Parameters:
      promise - The promise on which to delegate calls to.
      Returns:
      An Invocable Promise.