Class AsyncSupplier<T>

  • All Implemented Interfaces:
    java.util.function.Supplier<Optional<T>>

    @ThreadSafe
    public final class AsyncSupplier<T>
    extends Object
    implements java.util.function.Supplier<Optional<T>>
    Supplier that will evaluate a delegate supplier asynchronously, returning Optional.empty() until the underlying result is complete, at which point it will be returned. This computation is only initiated after the first call to get, but will be memoized infinitely after that. If the delegate throws, it will not be retried and Optional.empty() will be returned for the lifecycle of this supplier. Note that this class is responsible for creating and shutting down any executors. This class is thread safe by synchronising on get().
    • Method Detail

      • get

        public Optional<T> get()
        Specified by:
        get in interface java.util.function.Supplier<T>
      • create

        public static <T> AsyncSupplier<T> create​(java.util.function.Supplier<Optional<T>> delegate)