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.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Lazy
checkAlias()
void
checkBlank()
static Lazy<Object>
coerceToLazy(Object value)
static Object
force(Object arg)
Forces the argument, if needed, to a non-Lazy value.static Object
force(Object arg, Class target)
If argument is Lazy, force it, unless already an instance of target.static Object
force1(Object arg)
Forces the argument, if needed.T
getValue()
Return the actual value.boolean
isBlank()
static <T> Promise<T>
makeBlank()
static <T> Lazy<T>
makeBoundPromise(T value)
Wrap value as a forced Promise.void
print(Consumer out)
void
print(Appendable out)
void
setAlias(Lazy promise)
Bind promise to be an alias of another Lazy value.void
setException(Throwable exception)
Bind this promise so forcing it throws the given exception.void
setForceValueIfPromise(boolean value)
Set whether to recursively call getValue if getValue yields a Lazy value.void
setThunk(Procedure thunk)
Bind this promise so forcing it evaluates the given procedure.void
setValue(Object value)
Bind this promise to a given (eager) value.String
toString()
-
-
-
Constructor Detail
-
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 Detail
-
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.
-
getValue
public T getValue()
Description copied from interface:Lazy
Return the actual value. Note thatgetValue()
may returnthis
, if this object isn't actually lazy. It may also return another lazy value. Normally you should usePromise.force{val}
to extra a non-lazy (eager) value.
-
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. callsLazy.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. callsLazy.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.
-
print
public void print(Consumer out)
- Specified by:
print
in interfacegnu.kawa.format.Printable
-
print
public void print(Appendable out) throws IOException
- Throws:
IOException
-
-