Interface Promise.Invocable<R>

Type Parameters:
R - The result type
All Superinterfaces:
Invocable, Promise<R>
All Known Subinterfaces:
Blocker.Promise<C>
All Known Implementing Classes:
Promise.Invocable.Abstract, Promise.Invocable.NonBlocking
Enclosing interface:
Promise<C>

public static interface Promise.Invocable<R> extends Invocable, Promise<R>
  • Method Details

    • noop

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

      static <T> Callback toCallback(Promise.Invocable<T> promise, T result)

      Returns a new Callback that, when it is completed, completes the given promise.

      Parameters:
      promise - the promise to wrap
      result - the result to use to succeed the given promise when the Callback succeeds
      Returns:
      a new Callback wrapping the given promise
    • toPromise

      static <W, T> Promise.Invocable<W> toPromise(Promise.Invocable<T> promise, Function<W,T> mapper)

      Returns a new promise that, when it is completed, completes the given promise.

      Type Parameters:
      W - the wrapper type
      T - the promise type
      Parameters:
      promise - the promise to wrap
      mapper - a function that converts the result type
      Returns:
      a new promise wrapping the given promise
    • toPromise

      static <W> Promise.Invocable<W> toPromise(CompletableFuture<W> completable)

      Returns a new promise that, when it is completed, completes the given CompletableFuture.

      Type Parameters:
      W - the result type
      Parameters:
      completable - the CompletableFuture to complete
      Returns:
      a new promise
    • toBiConsumer

      static <R> BiConsumer<R,Throwable> toBiConsumer(Promise.Invocable<R> promise)

      Returns a BiConsumer that, when it is invoked, completes the given promise

      Typical usage is with CompletableFuture.whenComplete(BiConsumer):

      
       void example(Promise<T> promise) {
           CompletableFuture<T> completable = ...;
           completable.whenComplete(Promise.Invocable.toBiConsumer(promise));
       }
       
      Parameters:
      promise - the promise to wrap
    • from

      static <T> Promise.Invocable<T> from(Invocable.InvocationType invocationType, Consumer<T> success, Consumer<Throwable> failure)

      Factory method to create a promise from the given arguments.

      Type Parameters:
      T - the type of the promise result
      Parameters:
      invocationType - the Invocable.InvocationType of the promise
      success - the consumer to run upon success
      failure - the consumer to run upon failure
      Returns:
      a new promise
    • from

      static <T> Promise.Invocable<T> from(Invocable.InvocationType invocationType, BiConsumer<T,Throwable> consumer)

      Factory method to create a promise from the given arguments.

      Type Parameters:
      T - the type of the promise result
      Parameters:
      invocationType - the Invocable.InvocationType of the promise
      consumer - the consumer to run upon completion
      Returns:
      a new promise
    • from

      static <T> Promise.Invocable<T> from(Promise.Invocable<T> promise, Runnable afterComplete)

      Returns a promise that, when it is completed, completes the given promise and then runs the given Runnable.

      Type Parameters:
      T - the type of the promise result
      Parameters:
      promise - the promise to wrap
      afterComplete - the Runnable to run after completion
      Returns:
      a new promise wrapping the given promise
      See Also:
    • from

      static <T> Promise.Invocable<T> from(Runnable beforeComplete, Promise.Invocable<T> promise)

      Returns a promise that, when it is completed, runs the given Runnable and then completes the given promise.

      Type Parameters:
      T - the type of the promise result
      Parameters:
      beforeComplete - the Runnable to run before completion
      promise - the promise to wrap
      Returns:
      a new promise wrapping the given promise
      See Also: