T - The type of the value promised to be available now, or in the future, or never.public interface Promise<T>
Functions and Actions execute
on a Scheduler. Accordingly, a promise is thread-safe.| Modifier and Type | Method and Description |
|---|---|
void |
await()
Await the completion or the cancellation of the promise.
|
boolean |
await(long timeout,
java.util.concurrent.TimeUnit unit)
Await the completion or the cancellation of the promise at most the time specified.
|
void |
cancel()
Cancels the propagation of completion of the promise.
|
T |
get()
Returns the value promised upon completion.
|
java.lang.Throwable |
getError()
Returns the error promised upon completion.
|
boolean |
isCancelled()
Returns whether the promise has been cancelled.
|
boolean |
isDone()
Returns whether the promise has been completed.
|
boolean |
isSuccessful()
Returns whether the promise has completed and has no errors .
|
void |
set(T value)
Completes the promise with a value.
|
void |
setError(java.lang.Throwable error)
Completes the promise with an error.
|
void |
then(Scheduler scheduler,
Action<T> action)
Calls the action on the promise upon the completion of this promise.
|
<U> Promise<U> |
then(Scheduler scheduler,
Function<T,U> function)
Returns a new transformed promise specified by the function
upon the completion of this promise.
|
boolean isCancelled()
boolean isDone()
boolean isSuccessful()
void cancel()
void await()
throws java.lang.InterruptedException
java.lang.InterruptedException - If the thread awaiting on the promise is interrupted,
an exception is thrown.boolean await(long timeout,
java.util.concurrent.TimeUnit unit)
throws java.lang.InterruptedException
timeout - The duration at most to await.unit - The unit of duration to await.java.lang.InterruptedException - If the thread awaiting on the promise is interrupted,
an exception is thrown.T get() throws java.lang.IllegalStateException
java.lang.IllegalStateException - If this method is called before the completion of the promise,
an exception is thrown.java.lang.Throwable getError()
throws java.lang.IllegalStateException
java.lang.IllegalStateException - If this method is called before the completion of the promise,
an exception is thrown.void set(T value) throws java.lang.IllegalStateException
value - The value to complete the promise.java.lang.IllegalStateException - If this method is called after the completion of the promise,
an exception is thrown.void setError(java.lang.Throwable error)
throws java.lang.IllegalStateException
error - The error to complete the promise.java.lang.IllegalStateException - If this method is called after the completion of the promise,
an exception is thrown.<U> Promise<U> then(Scheduler scheduler, Function<T,U> function)
U - The new type of promise.scheduler - The scheduler to call the function.function - A function to transform the current promise into another promise.