public interface Promise<T,F,P> extends OnCancel, Future<T>
A read-only representation of a Deferred allowing listeners to be notified of state changes, though
clients are allowed to attempt to stop the computation using cancel(boolean).
Deferred| Modifier and Type | Method and Description |
|---|---|
boolean |
cancel(boolean interrupt)
Called to attempt to stop the computation.
|
boolean |
isCancelled() |
boolean |
isDone() |
boolean |
isRejected() |
boolean |
isResolved() |
Promise<T,F,P> |
onCancel(OnCancel then)
Triggered when
cancel(boolean) is the first terminal method called. |
Promise<T,F,P> |
onComplete(OnComplete then)
Triggered on any event after which
isDone() will return true. |
Promise<T,F,P> |
onGet(Future<?> then)
Triggered when
Future.get(long, java.util.concurrent.TimeUnit) or Future.get() is called. |
Promise<T,F,P> |
onProgress(OnProgress<P> then)
Triggered when
Deferred.progress(Object) is called. |
Promise<T,F,P> |
onReject(OnReject<F> then)
Triggered when
Deferred.reject(Object) is the first terminal method called. |
Promise<T,F,P> |
onResolve(OnResolve<T> then)
Triggered when
Deferred.resolve(Object) is the first terminal method called. |
boolean cancel(boolean interrupt)
throws ListenerException
Called to attempt to stop the computation. Calling this method does not guarantee that the computation will
cease however if this method is the first terminal method called, an implementation MUST guarantee that any
listeners will not by notified of calls to any other terminal methods. After this method has
been called isDone() will return true. If this was the first terminal method to be called
isCancelled() will also return true.
cancel in interface Future<T>cancel in interface OnCancelinterrupt - true If the computation should be interrupted in the case that it has already commenced.true If the promise was cancelled, false if it had already reached another terminal state.ListenerException - MAY be thrown if a listener throws an exception.Future.cancel(boolean)boolean isDone()
boolean isResolved()
true if Deferred.resolve(Object) was the first terminal method called.boolean isRejected()
true if Deferred.reject(Object) was the first terminal method called.boolean isCancelled()
isCancelled in interface Future<T>true if cancel(boolean) was the first terminal method called.Promise<T,F,P> onResolve(OnResolve<T> then)
Triggered when Deferred.resolve(Object) is the first terminal method called.
then - Callback to be executedPromise<T,F,P> onReject(OnReject<F> then)
Triggered when Deferred.reject(Object) is the first terminal method called.
then - Callback to be executedPromise<T,F,P> onCancel(OnCancel then)
Triggered when cancel(boolean) is the first terminal method called.
then - Callback to be executedPromise<T,F,P> onComplete(OnComplete then)
Triggered on any event after which isDone() will return true.
Will be fired in addition to the callback for the specific event.
then - Callback to be executedPromise<T,F,P> onProgress(OnProgress<P> then)
Triggered when Deferred.progress(Object) is called.
An implementation MUST ensure that the value from a call to Deferred.progress(Object) is reported to
every listener that is registered prior to that call. Values from calls to Deferred.progress(Object)
before this method was called MAY be sent to the listener. If they are they MUST be sent in the same order
they were received by Deferred.progress(Object);
then - Callback to be executedPromise<T,F,P> onGet(Future<?> then)
Triggered when Future.get(long, java.util.concurrent.TimeUnit) or Future.get() is called.
It will be called after this promise has transitioned into a state
where isDone() will return true.
Each get method will call the corresponding get method on the Future
in the thread that called either Future.get() or Future.get(long, java.util.concurrent.TimeUnit).
then - Callback to be executedCopyright © 2014 MachineCode. All rights reserved.