public class DelegatingPromise<T> extends java.lang.Object implements Promise<T>
Promise
method
invocations to a delegate promise.Constructor and Description |
---|
DelegatingPromise(Promise<T> delegate) |
Modifier and Type | Method and Description |
---|---|
void |
addListener(PromiseListener<T> listener)
Adds a listener to this promise that will be notified when the promise is
resolved.
|
void |
await()
Blocks the current thread for an unbounded amount of time until the promise
has be resolved.
|
boolean |
await(long time,
java.util.concurrent.TimeUnit unit)
Blocks the current thread for up to the specified amount of time or until
the promise has been resolved.
|
T |
get()
If the promise's value is set, then this method returns the value.
|
protected Promise<T> |
getDelegate() |
java.lang.Throwable |
getError()
Returns the error in this promise, if there is one.
|
T |
getOrDefault(T defaultValue)
Gets the value in this promise or, if the promise contains an error,
returns the given default value.
|
boolean |
isDone()
Returns
true if this promise is resolved. |
boolean |
isFailed()
Returns
true if the promise has an error. |
public T get() throws PromiseException
Promise
PromiseException
. If the promise has not yet been resolved (i.e.
it has no value and no error) then this method raises a
PromiseUnresolvedException
.get
in interface Promise<T>
PromiseException
- if the promise has an errorPromiseUnresolvedException
- if the promise has not yet been resolvedpublic java.lang.Throwable getError()
Promise
null
. If this
promise has no value and no error (i.e. it is unresolved) then a
PromiseUnresolvedException
is thrown.public T getOrDefault(T defaultValue)
Promise
If the promise has not been resolved then this method will throw
PromiseUnresolvedException
.
getOrDefault
in interface Promise<T>
defaultValue
- the default value to return if this promise contains an
error.public void await() throws java.lang.InterruptedException
Promise
For asynchronous workflows, use Promise.addListener(PromiseListener)
,
which will notify the user when the promise is resolved instead of blocking
the current thread.
public boolean await(long time, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
Promise
true
.
For asynchronous workflows, use Promise.addListener(PromiseListener)
,
which will notify the user when the promise is resolved instead of blocking
the current thread.
public void addListener(PromiseListener<T> listener)
Promise
Listener will be called on a thread that completed this promise.
The instance passed in to PromiseListener.onResolved(Promise)
method does not have to
be the exact same instance the PromiseListener
was registered with.
addListener
in interface Promise<T>
listener
- the listener to add to this promisepublic boolean isDone()
Promise
true
if this promise is resolved. A promise is resolved
when it has a value or an error.public boolean isFailed()
Promise
true
if the promise has an error. Errors can retrieved
using Promise.getError()
.