Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.
public final class AsyncResult<V>
- Object
- AsyncResult
ImplementsFuture<V>
A Future that is already complete: what an @Async method
returns from its body.
@Async
public Future build(String month) {
return AsyncResult.of(compute(month));
}
The caller never sees this object. It receives the Future of the call
itself at once, which completes with this value when the body has run –
the same arrangement as Spring’s AsyncResult and
CompletableFuture.completedFuture.
Methods
public static <V> AsyncResult<V> of(V value) | A result holding value. |
public static <V> AsyncResult<V> failed(Throwable failure) | A result that failed with failure, for a body that reports rather than throws. |
public boolean cancel(boolean mayInterruptIfRunning) | Stops the work if it has not started. |
public boolean isCancelled() | Whether cancel cancelled the work before it ran. |
public boolean isDone() | Whether the work has finished: completed, failed or cancelled. |
public V get()
throws ExecutionException | Waits for the work to finish and returns its result. |
public V get(long timeout, TimeUnit unit)
throws ExecutionException | Waits up to timeout for the work to finish and returns its result. |
Inherited methods
Method details
of
public static <V> AsyncResult<V> of(V value)A result holding
value.failed
public static <V> AsyncResult<V> failed(Throwable failure)A result that failed with
failure, for a body that reports rather than throws.cancel
public boolean cancel(boolean mayInterruptIfRunning)Stops the work if it has not started. Answers whether it was cancelled;
work already running is not interrupted by the backend’s executors.
Parameters
mayInterruptIfRunningboolean- whether a running task may be interrupted
Returns
true when this call cancelled it
isCancelled
public boolean isCancelled()Whether
cancel cancelled the work before it ran.Returns
true when cancelled
isDone
public boolean isDone()Whether the work has finished: completed, failed or cancelled.
Returns
true once it will not change again
get
public V get()
throws ExecutionExceptionWaits for the work to finish and returns its result.
Returns
the result
Throws
InterruptedException- when the waiting thread is interrupted
ExecutionException- when the work threw;
Throwable.getCauseis what it threw CancellationException- when the work was cancelled
get
public V get(long timeout, TimeUnit unit)
throws ExecutionExceptionWaits up to
timeout for the work to finish and returns its result.Parameters
timeoutlong- how long to wait, in
unit unitTimeUnit- the unit of
timeout
Returns
the result
Throws
InterruptedException- when the waiting thread is interrupted
ExecutionException- when the work threw
TimeoutException- when it has not finished in time
CancellationException- when the work was cancelled