MCPcopy Create free account
hub / github.com/angular/angular / createLoader

Function createLoader

packages/core/src/di/inject_async.ts:84–94  ·  view source on GitHub ↗

* Creates the memoized loader function in its own lexical scope so that the * prefetch callback does not share a closure context with `injector`.

(
  loader: () => Promise<InjectAsyncLoaderResult<T>>,
)

Source from the content-addressed store, hash-verified

82 * prefetch callback does not share a closure context with `injector`.
83 */
84function createLoader<T>(
85 loader: () => Promise<InjectAsyncLoaderResult<T>>,
86): () => Promise<InjectAsyncLoaderResult<T>> {
87 let loadedPromise: Promise<InjectAsyncLoaderResult<T>> | null = null;
88 return () => {
89 if (!loadedPromise) {
90 loadedPromise = loader();
91 }
92 return loadedPromise;
93 };
94}
95
96/**
97 * Interface for `options` argument used within `injectAsync` call.

Callers 1

injectAsyncFunction · 0.70

Calls 1

loaderFunction · 0.85

Tested by

no test coverage detected