T
- Type of the supplied calculations resultpublic interface AsyncResult<T>
Some long running calculations can provide meaningful, approximate intermediate results. Such long running,
possibly multithreaded (or even distributed) task results can be represented with a ListenableFuture
. When
intermediate results are also required, ListenableFuture
instances can provide a meaningful representation
for them.
To access the results of the calculation use getResult()
which returns the same reference for each
invocation.
Modifier and Type | Method and Description |
---|---|
ListenableFuture<T> |
createIntermediateResult()
Create a new intermediate result.
|
ListenableFuture<T> |
getResult()
Get the representation of the long running task.
|
ListenableFuture<T> getResult()
This is the final result of the represented task. The returned ListenableFuture is allocated when
this
AsyncResult is created; the same reference is returned on every invocation.
Cancellation by invoking Future.cancel(boolean)
on the returned reference cancels the underlying
calculations and intermediate results returned by subsequent createIntermediateResult()
calls. Non
completed intermediate results might or might not be cancelled. Cancel also can propagate from
ProgressObserver
passed when the given long running task started. Cancellation of partial results
never propagates to the final result.
ListenableFuture<T> createIntermediateResult()
The semantics of the intermediate results varies between implementations. An intermediate result can provide
the same result as the final one returned by getResult()
, the same time, however usually a new, lighter
asynchronous task is needed to collect the intermediate results. Note that the reference returned by this call is
always a new instance in order to mitigate cancel propagation.
Cancellation of intermediate results returned by this method never propagates to other intermediate results
returned by preceding or subsequent calls to this method, nor to the final result returned by
getResult()
. Cancellation of the final result or the ProgressObserver
observing the execution
might or might not propagate to intermediate results requested earlier.