Class Async<T>

java.lang.Object
org.praxislive.code.userapi.Async<T>
Type Parameters:
T - result type

public final class Async<T> extends Object
A lightweight holder for a future value, the result of an asynchronous operation such as an actor call. An Async can also reflect the failure of such an operation.

An Async can be explicitly completed, with a value or error. Completion can only happen once.

Async is not thread safe and is not designed for concurrent operation. Use from a single thread, or protect appropriately.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
    A queue for handling Async instances.
    static interface 
    A task intended to be run asynchronously and outside of the main component context.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Construct an empty Async.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    complete(T value)
    Complete the Async with the provided value.
    boolean
    Whether this Async has been completed, with or without error.
    Get the failure error or null.
    boolean
    fail(PError error)
    Complete the Async unsuccessfully with the provided error.
    boolean
    Whether this Async completed with a failure.
    Get the result of this Async if completed without error, otherwise null.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Async

      public Async()
      Construct an empty Async.
  • Method Details

    • result

      public T result()
      Get the result of this Async if completed without error, otherwise null.
      Returns:
      result or null
    • error

      public PError error()
      Get the failure error or null.
      Returns:
      error or null
    • done

      public boolean done()
      Whether this Async has been completed, with or without error.
      Returns:
      true if done
    • failed

      public boolean failed()
      Whether this Async completed with a failure.
      Returns:
      true if failed
    • complete

      public boolean complete(T value)
      Complete the Async with the provided value. If this Async is already completed, with or without failure, its state remains the same and this method returns false.
      Parameters:
      value - value to complete the Async
      Returns:
      true if completed
    • fail

      public boolean fail(PError error)
      Complete the Async unsuccessfully with the provided error. If this Async is already completed, with or without failure, its state remains the same and this method returns false.
      Parameters:
      error - error to complete the Async
      Returns:
      true if completed