Interface Promise<T>
- All Superinterfaces:
Completable<T>
- All Known Subinterfaces:
BaseBridgeEvent, BridgeEvent, BridgeEvent, BridgeEvent, ConnectionInitEvent
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).
- Author:
- Julien Viet
-
Method Summary
Modifier and TypeMethodDescriptiondefault voidcomplete()Callscomplete(null)default voidSet the result.default voidComplete this instance whenfailureisnull, a success is signaled otherwise a failure is signaleddefault voidCallsCompletable.fail(Throwable)with themessage.default voidSet the failure.future()default voidhandle(AsyncResult<T> asyncResult) Succeed or fail this promise with theAsyncResultevent.static <T> Promise<T> promise()Create a promise that hasn't completed yetdefault voidsucceed()Shortcut forsucceed(null)default voidSet the result.default booleanCallstryComplete(null).booleantryComplete(T result) Likecomplete(Object)but returnsfalsewhen the promise is already completed instead of throwing anIllegalStateException, it returnstrueotherwise.default booleanCallsfail(Throwable)with themessage.booleanLikefail(Throwable)but returnsfalsewhen the promise is already completed instead of throwing anIllegalStateException, it returnstrueotherwise.
-
Method Details
-
promise
Create a promise that hasn't completed yet- Type Parameters:
T- the result type- Returns:
- the promise
-
handle
Succeed or fail this promise with theAsyncResultevent.- Parameters:
asyncResult- the async result to handle
-
complete
Description copied from interface:CompletableComplete this instance- when
failureisnull, a success is signaled - otherwise a failure is signaled
- Specified by:
completein interfaceCompletable<T>- Parameters:
result- the resultfailure- the failure
- when
-
complete
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
Description copied from interface:CompletableSet the result. The instance will be marked as succeeded and completed.- Specified by:
succeedin interfaceCompletable<T>- Parameters:
result- the result
-
succeed
default void succeed()Description copied from interface:CompletableShortcut forsucceed(null)- Specified by:
succeedin interfaceCompletable<T>
-
fail
Description copied from interface:CompletableSet the failure. This instance will be marked as failed and completed.- Specified by:
failin interfaceCompletable<T>- Parameters:
failure- the failure
-
fail
Description copied from interface:CompletableCallsCompletable.fail(Throwable)with themessage.- Specified by:
failin interfaceCompletable<T>- Parameters:
message- the failure message
-
tryComplete
Likecomplete(Object)but returnsfalsewhen the promise is already completed instead of throwing anIllegalStateException, it returnstrueotherwise.- Parameters:
result- the result- Returns:
falsewhen the future is already completed
-
tryComplete
default boolean tryComplete()CallstryComplete(null).- Returns:
falsewhen the future is already completed
-
tryFail
Likefail(Throwable)but returnsfalsewhen the promise is already completed instead of throwing anIllegalStateException, it returnstrueotherwise.- Parameters:
cause- the failure cause- Returns:
falsewhen the future is already completed
-
tryFail
Callsfail(Throwable)with themessage.- Parameters:
message- the failure message- Returns:
- false when the future is already completed
-
future
-