UNPKG

@clerk/shared

Version:

Internal package utils used by the Clerk SDKs

28 lines (26 loc) 771 B
import { retry } from "./retry.mjs"; //#region src/safeImport.ts /** * Safely imports a module with automatic retries on failure. * Useful for dynamic imports that might fail due to network issues or temporary loading problems. * Retries up to 3 times with exponential backoff. * * @param importFn - A function that returns a dynamic import promise * @returns A promise that resolves to the imported module * * @example * ```typescript * const module = await safeImport(() => import('./my-module')); * ``` */ const safeImport = async (importFn) => { return retry(importFn, { initialDelay: 100, shouldRetry: (_, iterations) => iterations <= 3, retryImmediately: true, factor: 2 }); }; //#endregion export { safeImport }; //# sourceMappingURL=safeImport.mjs.map