public interface Promise<T> extends Handler<AsyncResult<T>>
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.
Modifier and Type | Method and Description |
---|---|
default void |
complete()
Calls
complete(null) |
default void |
complete(T result)
Set the result.
|
default void |
fail(String message)
Calls
fail(Throwable) with the message . |
default void |
fail(Throwable cause)
Set the failure.
|
Future<T> |
future() |
default void |
handle(AsyncResult<T> asyncResult)
Succeed or fail this promise with the
AsyncResult event. |
static <T> Promise<T> |
promise()
Create a promise that hasn't completed yet
|
default boolean |
tryComplete()
Calls
tryComplete(null) . |
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. |
default boolean |
tryFail(String message)
Calls
fail(Throwable) with the message . |
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. |
static <T> Promise<T> promise()
T
- the result typedefault void handle(AsyncResult<T> asyncResult)
AsyncResult
event.handle
in interface Handler<AsyncResult<T>>
asyncResult
- the async result to handledefault void complete(T result)
result
- the resultIllegalStateException
- when the promise is already completeddefault void complete()
complete(null)
IllegalStateException
- when the promise is already completeddefault void fail(Throwable cause)
cause
- the failure causeIllegalStateException
- when the promise is already completeddefault void fail(String message)
fail(Throwable)
with the message
.message
- the failure messageIllegalStateException
- when the promise is already completedboolean tryComplete(T result)
complete(Object)
but returns false
when the promise is already completed instead of throwing
an IllegalStateException
, it returns true
otherwise.result
- the resultfalse
when the future is already completeddefault boolean tryComplete()
tryComplete(null)
.false
when the future is already completedboolean tryFail(Throwable cause)
fail(Throwable)
but returns false
when the promise is already completed instead of throwing
an IllegalStateException
, it returns true
otherwise.cause
- the failure causefalse
when the future is already completeddefault boolean tryFail(String message)
fail(Throwable)
with the message
.message
- the failure messageCopyright © 2021 Eclipse. All rights reserved.