Class LatchedLazyFuture<X>

  • Type Parameters:
    X - result type
    All Implemented Interfaces:
    java.util.concurrent.Future<X>
    Direct Known Subclasses:
    LazyFuture

    public abstract class LatchedLazyFuture<X>
    extends java.lang.Object
    implements java.util.concurrent.Future<X>
    A simple calculation future for cross-thread result sharing and optional eager parallelism via withRunningThread().
    • Constructor Detail

      • LatchedLazyFuture

        public LatchedLazyFuture()
    • Method Detail

      • cancel

        public boolean cancel​(boolean mayInterruptIfRunning)
        Specified by:
        cancel in interface java.util.concurrent.Future<X>
      • isCancelled

        public boolean isCancelled()
        Specified by:
        isCancelled in interface java.util.concurrent.Future<X>
      • isDone

        public boolean isDone()
        Specified by:
        isDone in interface java.util.concurrent.Future<X>
      • get

        public X get()
              throws java.lang.InterruptedException,
                     java.util.concurrent.ExecutionException
        Specified by:
        get in interface java.util.concurrent.Future<X>
        Throws:
        java.lang.InterruptedException
        java.util.concurrent.ExecutionException
      • get

        public X get​(long timeout,
                     java.util.concurrent.TimeUnit unit)
              throws java.lang.InterruptedException,
                     java.util.concurrent.ExecutionException,
                     java.util.concurrent.TimeoutException
        Specified by:
        get in interface java.util.concurrent.Future<X>
        Throws:
        java.lang.InterruptedException
        java.util.concurrent.ExecutionException
        java.util.concurrent.TimeoutException
      • calculate

        protected abstract X calculate()
                                throws java.util.concurrent.ExecutionException,
                                       java.lang.InterruptedException
        Throws:
        java.util.concurrent.ExecutionException
        java.lang.InterruptedException
      • withRunningThread

        public LatchedLazyFuture<X> withRunningThread()
        spawns a new thread if not already started or done (otherwise, calculation happens in the first get call)
        Returns:
        this for chaining