public interface Promise<V> extends Future<V>
Future
which is writable.
A Promise
can be completed or canceled, cancellation is performed by the cancel
method.
Once a computation has completed, the computation cannot be cancelled. If you would like to use a Promise
for the sake of cancellability but not provide a usable result, you can declare type+s of the form
Promise<?>
and return null
as a result of the underlying task.
Modifier and Type | Method and Description |
---|---|
boolean |
cancel(boolean mayInterruptIfRunning)
Attempts to cancel execution of this task.
|
boolean |
set(V value)
Set the value to this promise and mark it completed if set successfully.
|
boolean |
setFailure(Throwable cause)
Marks this promise as a failure and notifies all listeners.
|
addListener, get, get, getThrowable, isCancelled, isDone
boolean cancel(boolean mayInterruptIfRunning)
cancel
is called, this task should never run. If the task has already started, then the mayInterruptIfRunning
parameter determines whether the thread executing this task should be interrupted in an
attempt to stop the task.
After this method returns, subsequent calls to Future.isDone()
will always return true
. Subsequent calls
to Future.isCancelled()
will always return true
if this method returned true
.
cancel
in interface Future<V>
mayInterruptIfRunning
- true
if the thread executing this task should be interrupted; otherwise,
in-progress tasks are allowed to completefalse
if the task could not be cancelled, typically because it has already completed normally;
true
otherwiseboolean set(V value)
value
- Valueboolean setFailure(Throwable cause)
cause
- the causeCopyright © 2017–2020 OpenMessaging. All rights reserved.