Top Description Methods
io.vertx.core

public Interface Promise<T>

extends Handler<AsyncResult<T>>
Known Direct Subinterfaces
io.vertx.core.impl.future.PromiseInternal
Annotations
@VertxGen
Imports
io.vertx.codegen.annotations.CacheReturn, .GenIgnore, .VertxGen, io.vertx.core.impl.NoStackTraceThrowable, io.vertx.core.impl.future.PromiseImpl

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 Handler<AsyncResult<T>> so it can be used as a callback.

Author
Julien Viet

Method Summary

Modifier and TypeMethod and Description
public default void
complete(T
the result
result
)

Set the result.

public default void
complete()

Calls complete(null)

public default void
fail(Throwable
the failure cause
cause
)

Set the failure.

public default void
fail(String
the failure message
message
)

Calls fail(Throwable) with the message.

public Future<T>

Returns:

the Future associated with this promise, it can be used to be aware of the promise completion
future
()

public default void
handle(AsyncResult<T>
the async result to handle
asyncResult
)

Implements io.vertx.core.Handler.handle.

Succeed or fail this promise with the AsyncResult event.

public static <
the result type
T
>
Promise<T>

Returns:

the promise
promise
()

Create a promise that hasn't completed yet

public boolean

Returns:

false when the future is already completed
tryComplete
(T
the result
result
)

Like complete(Object) but returns false when the promise is already completed instead of throwing an IllegalStateException, it returns true otherwise.

public default boolean

Returns:

false when the future is already completed
tryComplete
()

Calls tryComplete(null).

public boolean

Returns:

false when the future is already completed
tryFail
(Throwable
the failure cause
cause
)

Like fail(Throwable) but returns false when the promise is already completed instead of throwing an IllegalStateException, it returns true otherwise.

public default boolean

Returns:

false when the future is already completed
tryFail
(String
the failure message
message
)

Calls fail(Throwable) with the message.

Method Detail

completeback to summary
public default 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:T

the result

Exceptions
IllegalStateException:
when the promise is already completed
completeback to summary
public default void complete()

Calls complete(null)

Exceptions
IllegalStateException:
when the promise is already completed
failback to summary
public default void fail(Throwable cause)

Set the failure. Any handler will be called, if there is one, and the future will be marked as completed.

Parameters
cause:Throwable

the failure cause

Exceptions
IllegalStateException:
when the promise is already completed
failback to summary
public default void fail(String message)

Calls fail(Throwable) with the message.

Parameters
message:String

the failure message

Exceptions
IllegalStateException:
when the promise is already completed
futureback to summary
public Future<T> future()
Returns:Future<T>

the Future associated with this promise, it can be used to be aware of the promise completion

Annotations
@CacheReturn
handleback to summary
public default void handle(AsyncResult<T> asyncResult)

Implements io.vertx.core.Handler.handle.

Succeed or fail this promise with the AsyncResult event.

Parameters
asyncResult:AsyncResult<T>

the async result to handle

Annotations
@GenIgnore
@Override
promiseback to summary
public static <T> Promise<T> promise()

Create a promise that hasn't completed yet

Parameters
<T>
the result type
Returns:Promise<T>

the promise

tryCompleteback to summary
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:T

the result

Returns:boolean

false when the future is already completed

tryCompleteback to summary
public default boolean tryComplete()

Calls tryComplete(null).

Returns:boolean

false when the future is already completed

tryFailback to summary
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:Throwable

the failure cause

Returns:boolean

false when the future is already completed

tryFailback to summary
public default boolean tryFail(String message)

Calls fail(Throwable) with the message.

Parameters
message:String

the failure message

Returns:boolean

false when the future is already completed