@neutrium/utilities - v3.1.0
    Preparing search index...

    Class AsyncLazy<T>

    Share one asynchronous initialization and retain accepted results, including undefined. Rejections are never retained. clear() invalidates the current attempt without cancelling it; existing callers still receive its result. An old attempt cannot replace or clear a newer one. Do not await this instance's get() inside its factory or retention predicate.

    Type Parameters

    • T
    Index
    • Type Parameters

      • T

      Parameters

      • factory: () => T | PromiseLike<T>

        Invoked in a microtask on the first get() after construction or invalidation. Synchronous throws and rejected thenables become get() rejections.

      • shouldCache: (value: Awaited<T>) => boolean = ...

        Optional synchronous predicate, evaluated once per successful attempt. False delivers the value without retaining it. A throw or nonboolean result rejects the attempt and allows retry. Defaults to retaining all fulfilled results.

      Returns AsyncLazy<T>

    • Forget the pending or fulfilled attempt. Does not cancel work or dispose its result.

      Returns void

    • Return the same Promise for all callers until rejection, rejected retention, or clear().

      Returns Promise<Awaited<T>>