Class Promise<T>

java.lang.Object
io.vertx.mutiny.core.Promise<T>
All Implemented Interfaces:
MutinyDelegate
Direct Known Subclasses:
ConnectionInitEvent

public class Promise<T> extends Object implements MutinyDelegate
Represents the writable side of an action that may, or may not, have occurred yet.

The future() method returns the Future associated with a promise, the future can be used for getting notified of the promise completion and retrieve its value.

A promise extends Completable so it can be used with Future.onComplete(Completable).

NOTE: This class has been automatically generated from the original non Mutiny-ified interface.

Author:
Julien Viet
See Also:
  • Promise
  • Field Details

    • __TYPE_ARG

      public static final TypeArg<Promise> __TYPE_ARG
    • __typeArg_0

      public final TypeArg<T> __typeArg_0
  • Constructor Details

    • Promise

      public Promise(io.vertx.core.Promise<T> delegate)
      Create a new instance of Promise delegating to the given (non-null) instance of Promise.
    • Promise

      public Promise(io.vertx.core.Promise<T> delegate, TypeArg<T> typeArg_0)
    • Promise

      public Promise(Object delegate, TypeArg<T> typeArg_0)
  • Method Details

    • getDelegate

      public io.vertx.core.Promise<T> getDelegate()
      Get the delegate instance.

      This method returns the instance on which this shim is delegating the calls. And so, give you access to the bare API.

      Specified by:
      getDelegate in interface MutinyDelegate
      Returns:
      the delegate instance
    • future

      @CheckReturnValue public io.smallrye.mutiny.Uni<T> future()

      Unlike the bare Vert.x variant, this method returns a Uni. The uni emits the result of the operation as item. If the operation fails, the uni emits the failure.

      Don't forget to subscribe on it to trigger the operation.

      Returns:
      A Uni representing the asynchronous result of this operation.
      See Also:
      • Promise.future()
    • futureAndAwait

      public T futureAndAwait()

      Unlike the bare Vert.x variant, this method returns a Promise. This method awaits indefinitely for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

      Returns:
      The operation result
      See Also:
      • Promise.future()
    • futureAndForget

      public Promise<T> futureAndForget()

      Unlike the bare Vert.x variant, this method ignores the Promise result or any failure.

      Returns:
      The current instance to chain operations if needed.
      See Also:
      • Promise.future()
    • promise

      public static <T> Promise<T> promise()
      Create a promise that hasn't completed yet
      Type Parameters:
      T - the result type
      Returns:
      the promise
    • handle

      public void handle(io.vertx.core.AsyncResult<T> asyncResult)
      Succeed or fail this promise with the AsyncResult event.
      Parameters:
      asyncResult - the async result to handle
    • complete

      public void complete(T result, Throwable failure)
    • complete

      public void complete(T result)
      Set the result. Any handler will be called, if there is one, and the promise will be marked as completed.

      Any handler set on the associated promise will be called.

      Parameters:
      result - the result
      Throws:
      when - the promise is already completed
    • complete

      public void complete()
      Calls complete(null)
      Throws:
      when - the promise is already completed
    • succeed

      public void succeed(T result)
    • succeed

      public void succeed()
    • fail

      public void fail(Throwable failure)
    • fail

      public void fail(String message)
    • tryComplete

      public boolean tryComplete(T result)
      Like complete(Object) but returns false when the promise is already completed instead of throwing an IllegalStateException, it returns true otherwise.
      Parameters:
      result - the result
      Returns:
      false when the future is already completed
    • tryComplete

      public boolean tryComplete()
      Calls tryComplete(null).
      Returns:
      false when the future is already completed
    • tryFail

      public boolean tryFail(Throwable cause)
      Like fail(Throwable) but returns false when the promise is already completed instead of throwing an IllegalStateException, it returns true otherwise.
      Parameters:
      cause - the failure cause
      Returns:
      false when the future is already completed
    • tryFail

      public boolean tryFail(String message)
      Calls fail(Throwable) with the message.
      Parameters:
      message - the failure message
      Returns:
      false when the future is already completed
    • newInstance

      public static <T> Promise<T> newInstance(io.vertx.core.Promise<T> delegate)
      Creates a new instance of the Promise.
    • newInstance

      public static <T> Promise<T> newInstance(io.vertx.core.Promise<T> delegate, TypeArg<T> typeArg_0)
      Creates a new instance of the Promise.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object