Package ghidra.async

Class AsyncLazyValue<T>

java.lang.Object
ghidra.async.AsyncLazyValue<T>
Type Parameters:
T - the type of the value

public class AsyncLazyValue<T> extends Object
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 Details

    • AsyncLazyValue

      public AsyncLazyValue(Supplier<CompletableFuture<T>> supplier)
      Construct a lazy value for the given computation
      Parameters:
      supplier - specifies the computation
  • Method Details

    • request

      public CompletableFuture<T> request()
      Request the value If this is called before provide(), the computation given at construction is launched. The CompletableFuture it provides is returned immediately. Subsequent calls to either request() or provide() return the same future without starting any new computation.
      Returns:
      a future, possibly already completed, for the value
    • provide

      public CompletableFuture<T> provide()
      Provide the value out of band If this is called before request(), the computation given at construction is ignored. A new CompletableFuture is returned instead. The caller must see to this future's completion. Subsequent calls to either request() or provide() 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

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

      public boolean isBusy()
      Check if the value has been requested, but not yet completed

      This will also return true if something is providing the value out of band.

      Returns:
      true if request() or provide() has been called, but not completed
    • isDone

      public boolean isDone()
      Check if the value is available immediately
      Returns:
      true if request() or provide() has been called and completed.