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 |
---|---|
void |
complete()
Calls
complete(null) |
void |
complete(T result)
Set the result.
|
void |
fail(String message)
Calls
fail(Throwable) with the message . |
void |
fail(Throwable cause)
Set the failure.
|
Future<T> |
future() |
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
|
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. |
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 typevoid handle(AsyncResult<T> asyncResult)
AsyncResult
event.handle
in interface Handler<AsyncResult<T>>
asyncResult
- the async result to handlevoid complete(T result)
result
- the resultIllegalStateException
- when the promise is already completedvoid complete()
complete(null)
IllegalStateException
- when the promise is already completedvoid fail(Throwable cause)
cause
- the failure causeIllegalStateException
- when the promise is already completedvoid 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 completedboolean 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 completedboolean tryFail(String message)
fail(Throwable)
with the message
.message
- the failure messageCopyright © 2023 Eclipse. All rights reserved.