Class AsyncResult<V>

java.lang.Object
com.codename1.backend.AsyncResult<V>
All Implemented Interfaces:
Future<V>

public final class AsyncResult<V> extends Object implements Future<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.

  • 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)
      Description copied from interface: Future
      Stops the work if it has not started. Answers whether it was cancelled; work already running is not interrupted by the backend's executors.
      Specified by:
      cancel in interface Future<V>
      Parameters:
      mayInterruptIfRunning - whether a running task may be interrupted
      Returns:
      true when this call cancelled it
    • isCancelled

      public boolean isCancelled()
      Description copied from interface: Future
      Whether Future.cancel(boolean) cancelled the work before it ran.
      Specified by:
      isCancelled in interface Future<V>
      Returns:
      true when cancelled
    • isDone

      public boolean isDone()
      Description copied from interface: Future
      Whether the work has finished: completed, failed or cancelled.
      Specified by:
      isDone in interface Future<V>
      Returns:
      true once it will not change again
    • get

      public V get() throws ExecutionException
      Description copied from interface: Future
      Waits for the work to finish and returns its result.
      Specified by:
      get in interface Future<V>
      Returns:
      the result
      Throws:
      ExecutionException - when the work threw; Throwable.getCause() is what it threw
    • get

      public V get(long timeout, TimeUnit unit) throws ExecutionException
      Description copied from interface: Future
      Waits up to timeout for the work to finish and returns its result.
      Specified by:
      get in interface Future<V>
      Parameters:
      timeout - how long to wait, in unit
      unit - the unit of timeout
      Returns:
      the result
      Throws:
      ExecutionException - when the work threw