|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.rice.cs.plt.lambda.CachedThunk<R>
public class CachedThunk<R>
A thunk that caches the result of a nested thunk on the first invocation of value().
Unlike LazyThunk, the cached result can be invalidated by invoking reset(); the
next invocation of value() will again delegate to the nested thunk (the trade-off for
this behavior is that the wrapped thunk cannot be discarded for the life of this object).
If an exception occurs during evaluation, no result is cached.
Evaluation is thread-safe: locking guarantees that the nested thunk will never be evaluated (and
terminate normally) twice without an intervening reset() invocation. Thus, if two threads
invoke value() simultaneously (and a result is not cached), one will block until
the other resolves the nested thunk.
LazyThunk,
DelayedThunk,
LazyRunnable| Constructor Summary | |
|---|---|
CachedThunk(Thunk<? extends R> value)
|
|
| Method Summary | ||
|---|---|---|
Option<R> |
cachedValue()
Combines isResolved() and value() in an atomic operation (avoiding inconsistencies
due to a concurrent reset()): if a value is cached, return it; otherwise, return "none". |
|
boolean |
isResolved()
Test whether the thunk is in a "resolved" state. |
|
static
|
make(Thunk<? extends R> value)
|
|
void |
reset()
|
|
R |
value()
|
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public CachedThunk(Thunk<? extends R> value)
| Method Detail |
|---|
public R value()
value in interface Thunk<R>public void reset()
public boolean isResolved()
ResolvingThunktrue, an invocation of value
will return promptly and without exception.
isResolved in interface ResolvingThunk<R>public Option<R> cachedValue()
isResolved() and value() in an atomic operation (avoiding inconsistencies
due to a concurrent reset()): if a value is cached, return it; otherwise, return "none".
public static <R> CachedThunk<R> make(Thunk<? extends R> value)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||