Package gnu.mapping

Class Promise<T>

java.lang.Object
gnu.mapping.Promise<T>
All Implemented Interfaces:
gnu.kawa.format.Printable, Lazy<T>

public class Promise<T> extends Object implements gnu.kawa.format.Printable, Lazy<T>
Implement Scheme "promises". This is a final class, because in some cases (as required by SRFI-45) we copy the fields of one Promise from other Promise, and such copying would be dubious if either operand is a sub-class.
  • Constructor Details

    • Promise

      public Promise()
      Create new "blank" Promise. Calling getValue just waits until one of setValue, setAlias, setException or setThunk is invoked. One of these is typically done by some other "producer" thread.
    • Promise

      public Promise(Procedure thunk)
      Create a new Promise that will evaluate thunk when forced.
  • Method Details

    • setForceValueIfPromise

      public void setForceValueIfPromise(boolean value)
      Set whether to recursively call getValue if getValue yields a Lazy value.
    • makeBlank

      public static <T> Promise<T> makeBlank()
    • makeBoundPromise

      public static <T> Lazy<T> makeBoundPromise(T value)
      Wrap value as a forced Promise.
    • coerceToLazy

      public static Lazy<Object> coerceToLazy(Object value)
    • getValue

      public T getValue()
      Description copied from interface: Lazy
      Return the actual value. Note that getValue() may return this, if this object isn't actually lazy. It may also return another lazy value. Normally you should use Promise.force{val} to extra a non-lazy (eager) value.
      Specified by:
      getValue in interface Lazy<T>
    • isBlank

      public final boolean isBlank()
    • checkBlank

      public void checkBlank()
    • setValue

      public void setValue(Object value)
      Bind this promise to a given (eager) value.
    • setAlias

      public void setAlias(Lazy promise)
      Bind promise to be an alias of another Lazy value.
    • setException

      public void setException(Throwable exception)
      Bind this promise so forcing it throws the given exception.
    • setThunk

      public void setThunk(Procedure thunk)
      Bind this promise so forcing it evaluates the given procedure.
    • checkAlias

      public Lazy checkAlias()
    • force1

      public static Object force1(Object arg)
      Forces the argument, if needed. I.e. calls Lazy.getValue() once if the argument is Lazy.
    • force

      public static Object force(Object arg)
      Forces the argument, if needed, to a non-Lazy value. I.e. calls Lazy.getValue() as many times as needed.
    • force

      public static Object force(Object arg, Class target)
      If argument is Lazy, force it, unless already an instance of target.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • print

      public void print(Consumer out)
      Specified by:
      print in interface gnu.kawa.format.Printable
    • print

      public void print(Appendable out) throws IOException
      Throws:
      IOException