@clerk/shared
Version:
Internal package utils used by the Clerk SDKs
29 lines (27 loc) • 875 B
JavaScript
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const require_retry = require('./retry.js');
//#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 require_retry.retry(importFn, {
initialDelay: 100,
shouldRetry: (_, iterations) => iterations <= 3,
retryImmediately: true,
factor: 2
});
};
//#endregion
exports.safeImport = safeImport;
//# sourceMappingURL=safeImport.js.map