Class 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 class  Async.Queue<T>
      A queue for handling Async instances.
      static interface  Async.Task<T,​R>
      A task intended to be run asynchronously and outside of the main component context.
    • Constructor Summary

      Constructors 
      Constructor Description
      Async()
      Construct an empty Async.
    • Constructor Detail

      • Async

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

      • 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