T
- The type of the resultpublic class Promise<T> extends Object
Future
.
Promise and Future
are two complementary concepts. They are designed
to synchronize data between multiples threads. The Future
holds the
result of an asynchronous computation, from which you can retrieve the value
of the result; the Promise sets the value of this computation, which resolves
the associated Future
.
For promises that don't need a value and are just used to ensure correct
ordering of asynchronous operations, the common pattern to use is
Void
as a generic type.
Warning:
After a call of setValue(Object)
, setError(String)
or setCancelled()
,
it is illegal to call any of them
Modifier and Type | Class and Description |
---|---|
static interface |
Promise.CancelRequestCallback<T>
|
Constructor and Description |
---|
Promise() |
Promise(FutureCallbackType type)
Create a new promise
|
Modifier and Type | Method and Description |
---|---|
void |
connectFromFuture(Future<T> future) |
protected void |
finalize()
Called by garbage collector when object destroy.
Override to free the reference in JNI. |
Future<T> |
getFuture() |
void |
setCancelled()
Set the promise on cancel state and transfer the information to linked future.
Warning after call this method, call setValue(Object) , setError(String) or setCancelled() will cause an IllegalStateException |
void |
setError(String errorMessage)
Set the promise on error state and transfer the information to linked future.
Warning after call this method, call setValue(Object) , setError(String) or setCancelled() will cause an IllegalStateException |
void |
setOnCancel(Promise.CancelRequestCallback<T> callback)
Sets a cancel callback.
|
void |
setValue(T value)
Set the promise value and transfer the information to linked future.
Warning after call this method, call setValue(Object) , setError(String) or setCancelled() will cause an IllegalStateException |
public Promise(FutureCallbackType type)
type
- Callback typepublic Promise()
public void setValue(T value)
setValue(Object)
, setError(String)
or setCancelled()
will cause an IllegalStateExceptionvalue
- Promise valueIllegalStateException
- If setValue(Object)
, setError(String)
or setCancelled()
was previously calledpublic void setError(String errorMessage)
setValue(Object)
, setError(String)
or setCancelled()
will cause an IllegalStateExceptionerrorMessage
- Error messageIllegalStateException
- If setValue(Object)
, setError(String)
or setCancelled()
was previously calledpublic void setCancelled()
setValue(Object)
, setError(String)
or setCancelled()
will cause an IllegalStateExceptionIllegalStateException
- If setValue(Object)
, setError(String)
or setCancelled()
was previously calledpublic void setOnCancel(Promise.CancelRequestCallback<T> callback)
callback
- The callback to callCopyright © 2020. All rights reserved.