Helper for use cases in which the maker function is async. For two provideLazy calls with the same key, one may be making when the other call starts and it would make again. (Then there'd be a collision when the second tries to store the key.) This prevents that race condition by immediately storing a Promise for the maker in an ephemeral store.

When the store argument is durable storage, note that it's possible for termination to happen after the make completes and before it reaches durable storage.

  • Type Parameters

    • K extends Key
    • V extends Passable

    Parameters

    Returns {
        provideAsync: ((key: K, makeValue: ((key: K) => Promise<V>), finishValue?: ((key: K, value: V) => Promise<void>)) => Promise<V>);
    }

    • provideAsync: ((key: K, makeValue: ((key: K) => Promise<V>), finishValue?: ((key: K, value: V) => Promise<void>)) => Promise<V>)
        • (key, makeValue, finishValue?): Promise<V>
        • Call provideAsync to get or make the value associated with the key, when the maker is asynchronous. If there already is one, return that. Otherwise, call makeValue(key), remember it as the value for that key, and return it.

          Parameters

          • key: K
          • makeValue: ((key: K) => Promise<V>)

            make the value for the store if it hasn't been made yet or the last make failed

              • (key): Promise<V>
              • Parameters

                • key: K

                Returns Promise<V>

          • OptionalfinishValue: ((key: K, value: V) => Promise<void>)

            runs exactly once after a new value is added to the store

              • (key, value): Promise<void>
              • Parameters

                • key: K
                • value: V

                Returns Promise<void>

          Returns Promise<V>