Class Val<V>

  • All Implemented Interfaces:
    java.util.concurrent.Future<V>

    public class Val<V>
    extends java.lang.Object
    implements java.util.concurrent.Future<V>
    A dataflow constant. Represents a delayed value that can be set at most once, and when read, blocks until a value has been set.
    • Constructor Detail

      • Val

        public Val​(SuspendableCallable<V> f)
        Creates a Val whose value will be the one returned by the given SuspendableCallable, which will be spawned into a new fiber.

        Parameters:
        f - The function that will compute this Val's value in a newly spawned fiber
      • Val

        public Val​(FiberScheduler scheduler,
                   SuspendableCallable<V> f)
        Creates a Val whose value will be the one returned by the given SuspendableCallable, which will be spawned into a new fiber, scheduled by the given FiberScheduler.

        Parameters:
        scheduler - the scheduler in which the new fiber will be spawned.
        f - The function that will compute this Val's value in a newly spawned fiber
      • Val

        public Val()
    • Method Detail

      • set

        public final void set​(V value)
        Sets the value. If the value has already been set (or if a function has been supplied to the constructor), this method will throw an IllegalStateException. However, you should not rely on this behavior, as the implementation is free to silently ignore additional attempts to set the value.
        Parameters:
        value - the value
        Throws:
        java.lang.IllegalStateException - if the value has already been set.
      • setException

        public final void setException​(java.lang.Throwable t)
        Sets an exception that will be thrown by get, wrapped by RuntimeExecutionException.
        Parameters:
        t - the exception
        Throws:
        java.lang.IllegalStateException - if the value has already been set.
      • isDone

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

        @Suspendable
        public V get()
              throws java.lang.InterruptedException
        Returns the delayed value, blocking until it has been set.
        Specified by:
        get in interface java.util.concurrent.Future<V>
        Returns:
        the value
        Throws:
        java.lang.InterruptedException
      • get

        @Suspendable
        public V get​(long timeout,
                     java.util.concurrent.TimeUnit unit)
              throws java.lang.InterruptedException,
                     java.util.concurrent.TimeoutException
        Returns the delayed value, blocking until it has been set, but no longer than the given timeout.
        Specified by:
        get in interface java.util.concurrent.Future<V>
        Parameters:
        timeout - The maximum duration to block waiting for the value to be set.
        unit - The time unit of the timeout value.
        Returns:
        the value
        Throws:
        java.util.concurrent.TimeoutException - if the timeout expires before the value is set.
        java.lang.InterruptedException
      • get

        @Suspendable
        public V get​(Timeout timeout)
              throws java.lang.InterruptedException,
                     java.util.concurrent.TimeoutException
        Throws:
        java.lang.InterruptedException
        java.util.concurrent.TimeoutException
      • cancel

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

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