Package io.vertx.core
Interface Promise<T>
-
- All Superinterfaces:
Completable<T>
- All Known Subinterfaces:
BaseBridgeEvent
,BridgeEvent
,BridgeEvent
,ConnectionInitEvent
public interface Promise<T> extends Completable<T>
Represents the writable side of an action that may, or may not, have occurred yet.The
future()
method returns theFuture
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
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default void
complete()
Callscomplete(null)
default void
complete(T result)
Set the result.default void
complete(T result, Throwable failure)
Complete this instance whenfailure
isnull
, a success is signaled otherwise a failure is signaleddefault void
fail(String message)
CallsCompletable.fail(Throwable)
with themessage
.default void
fail(Throwable failure)
Set the failure.Future<T>
future()
default void
handle(AsyncResult<T> asyncResult)
Succeed or fail this promise with theAsyncResult
event.static <T> Promise<T>
promise()
Create a promise that hasn't completed yetdefault void
succeed()
Shortcut forsucceed(null)
default void
succeed(T result)
Set the result.default boolean
tryComplete()
CallstryComplete(null)
.boolean
tryComplete(T result)
Likecomplete(Object)
but returnsfalse
when the promise is already completed instead of throwing anIllegalStateException
, it returnstrue
otherwise.default boolean
tryFail(String message)
Callsfail(Throwable)
with themessage
.boolean
tryFail(Throwable cause)
Likefail(Throwable)
but returnsfalse
when the promise is already completed instead of throwing anIllegalStateException
, it returnstrue
otherwise.
-
-
-
Method Detail
-
promise
static <T> Promise<T> promise()
Create a promise that hasn't completed yet- Type Parameters:
T
- the result type- Returns:
- the promise
-
handle
default void handle(AsyncResult<T> asyncResult)
Succeed or fail this promise with theAsyncResult
event.- Parameters:
asyncResult
- the async result to handle
-
complete
default void complete(T result, Throwable failure)
Description copied from interface:Completable
Complete this instance- when
failure
isnull
, a success is signaled - otherwise a failure is signaled
- Specified by:
complete
in interfaceCompletable<T>
- Parameters:
result
- the resultfailure
- the failure
- when
-
complete
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
- the result- Throws:
IllegalStateException
- when the promise is already completed
-
complete
default void complete()
Callscomplete(null)
- Throws:
IllegalStateException
- when the promise is already completed
-
succeed
default void succeed(T result)
Description copied from interface:Completable
Set the result. The instance will be marked as succeeded and completed.- Specified by:
succeed
in interfaceCompletable<T>
- Parameters:
result
- the result
-
succeed
default void succeed()
Description copied from interface:Completable
Shortcut forsucceed(null)
- Specified by:
succeed
in interfaceCompletable<T>
-
fail
default void fail(Throwable failure)
Description copied from interface:Completable
Set the failure. This instance will be marked as failed and completed.- Specified by:
fail
in interfaceCompletable<T>
- Parameters:
failure
- the failure
-
fail
default void fail(String message)
Description copied from interface:Completable
CallsCompletable.fail(Throwable)
with themessage
.- Specified by:
fail
in interfaceCompletable<T>
- Parameters:
message
- the failure message
-
tryComplete
boolean tryComplete(T result)
Likecomplete(Object)
but returnsfalse
when the promise is already completed instead of throwing anIllegalStateException
, it returnstrue
otherwise.- Parameters:
result
- the result- Returns:
false
when the future is already completed
-
tryComplete
default boolean tryComplete()
CallstryComplete(null)
.- Returns:
false
when the future is already completed
-
tryFail
boolean tryFail(Throwable cause)
Likefail(Throwable)
but returnsfalse
when the promise is already completed instead of throwing anIllegalStateException
, it returnstrue
otherwise.- Parameters:
cause
- the failure cause- Returns:
false
when the future is already completed
-
tryFail
default boolean tryFail(String message)
Callsfail(Throwable)
with themessage
.- Parameters:
message
- the failure message- Returns:
- false when the future is already completed
-
-