Interface Promise<C>

Type Parameters:
C - the type of the promise result
All Known Subinterfaces:
Blocker.Promise<C>, Promise.Invocable<R>
All Known Implementing Classes:
FuturePromise, Promise.Completable, Promise.Invocable.Abstract, Promise.Invocable.NonBlocking, Promise.Task, Promise.Wrapper

public interface Promise<C>

An abstraction for a completed/failed result of an asynchronous operation.

  • Method Details

    • succeeded

      default void succeeded(C result)

      Callback method to invoke when the operation succeeds.

      Parameters:
      result - the operation result
      See Also:
    • failed

      default void failed(Throwable x)

      Callback method to invoke when the operation fails.

      Parameters:
      x - the operation failure
    • noop

      static <T> Promise<T> noop()
      Type Parameters:
      T - the type of the promise result
      Returns:
      a promise that performs no operations.
    • completeWith

      static <T> void completeWith(Promise<T> promise, CompletableFuture<T> completable)

      Completes the given promise with the given CompletableFuture.

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

      Parameters:
      promise - the promise to complete
      completable - the CompletableFuture that completes the 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 <T> Promise<T> from(Runnable complete)
      Creates a promise that runs the given Runnable when it succeeds or fails.
      Parameters:
      complete - The completion task to run on success or failure
      Returns:
      a new promise