mirror of
https://bitbucket.org/siakitem/my-pi.git
synced 2026-08-28 08:35:57 +00:00
chore: initialize my-pi extension bundle
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* Creates a memoized lazy loader for a dynamically imported module.
|
||||
*
|
||||
* The first call triggers `import(specifier)`; subsequent calls reuse the
|
||||
* cached promise. This avoids re-importing the module on every invocation
|
||||
* while keeping the heavy module out of the synchronous startup path.
|
||||
*/
|
||||
export function createLazyModuleLoader<T>(specifier: string): () => Promise<T> {
|
||||
let cached: Promise<T> | undefined;
|
||||
return (): Promise<T> => {
|
||||
cached ??= import(specifier) as Promise<T>;
|
||||
return cached;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user