aboutsummaryrefslogtreecommitdiff
path: root/src/utils/lazy.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils/lazy.ts')
-rw-r--r--src/utils/lazy.ts14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/utils/lazy.ts b/src/utils/lazy.ts
index 55aae5e..4bac45b 100644
--- a/src/utils/lazy.ts
+++ b/src/utils/lazy.ts
@@ -16,9 +16,17 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-export function makeLazy<T>(factory: () => T): () => T {
+export function makeLazy<T>(factory: () => T, attempts = 5): () => T {
+ let tries = 0;
let cache: T;
- return () => cache ?? (cache = factory());
+ return () => {
+ if (!cache && attempts > tries++) {
+ cache = factory();
+ if (!cache && attempts === tries)
+ console.error("Lazy factory failed:", factory);
+ }
+ return cache;
+ };
}
// Proxies demand that these properties be unmodified, so proxyLazy
@@ -85,6 +93,8 @@ export function proxyLazy<T>(factory: () => T, attempts = 5): T {
[kGET]() {
if (!proxyDummy[kCACHE] && attempts > tries++) {
proxyDummy[kCACHE] = factory();
+ if (!proxyDummy[kCACHE] && attempts === tries)
+ console.error("Lazy factory failed:", factory);
}
return proxyDummy[kCACHE];
}