Package ghidra.async
Class AsyncLazyValue<T>
java.lang.Object
ghidra.async.AsyncLazyValue<T>
- Type Parameters:
T
- the type of the value
A value to be completed once upon the first request, asynchronously
This contains a single lazy value. It is computed only if requested. When requested, a future is
returned and the computation is started. If the computation succeeds, the completed future is
cached indefinitely. Any subsequent requests return the same future, even if the computation has
not yet completed. Thus, when it completes, all requests will be fulfilled by the result of the
first request. If the computation completes exceptionally, the result is immediately discarded.
Thus, a subsequent request will retry the computation.
-
Constructor Summary
ConstructorsConstructorDescriptionAsyncLazyValue
(Supplier<CompletableFuture<T>> supplier) Construct a lazy value for the given computation -
Method Summary
Modifier and TypeMethodDescriptionvoid
forget()
Forget the value Instead of returning a completed (or even in-progress) future, the next request will cause the value to be re-computed.boolean
isBusy()
Check if the value has been requested, but not yet completedboolean
isDone()
Check if the value is available immediatelyprovide()
Provide the value out of band If this is called beforerequest()
, the computation given at construction is ignored.request()
Request the value If this is called beforeprovide()
, the computation given at construction is launched.toString()
-
Constructor Details
-
AsyncLazyValue
Construct a lazy value for the given computation- Parameters:
supplier
- specifies the computation
-
-
Method Details
-
request
Request the value If this is called beforeprovide()
, the computation given at construction is launched. TheCompletableFuture
it provides is returned immediately. Subsequent calls to eitherrequest()
orprovide()
return the same future without starting any new computation.- Returns:
- a future, possibly already completed, for the value
-
provide
Provide the value out of band If this is called beforerequest()
, the computation given at construction is ignored. A newCompletableFuture
is returned instead. The caller must see to this future's completion. Subsequent calls to eitherrequest()
orprovide()
return this same future without starting any computation. Under normal circumstances, the caller cannot determine whethor or not is has "claimed" the computation. If the usual computation is already running, then the computations are essentially in a race. As such, it is essential that alternative computations result in the same value as the usual computation. In other words, the functions must not differ, but the means of computation can differ. Otherwise, race conditions may arise.- Returns:
- a promise that the caller must fulfill or arrange to have fulfilled
-
forget
public void forget()Forget the value Instead of returning a completed (or even in-progress) future, the next request will cause the value to be re-computed. -
toString
-
isBusy
public boolean isBusy()Check if the value has been requested, but not yet completedThis will also return true if something is providing the value out of band.
-
isDone
public boolean isDone()Check if the value is available immediately
-