Fix makeLazy not incrementing tries if factory errors

This commit is contained in:
Nuckyz 2024-05-15 23:06:21 -03:00
parent 7f5aaada88
commit 4feaa40de7
No known key found for this signature in database
GPG key ID: 440BF8296E1C4AD9

View file

@ -20,9 +20,10 @@ export function makeLazy<T>(factory: () => T, attempts = 5, { isIndirect = false
const getter = () => { const getter = () => {
if (!cache && attempts > tries) { if (!cache && attempts > tries) {
tries++;
cache = factory(); cache = factory();
if (!cache && attempts === ++tries && !isIndirect) { if (!cache && attempts === tries && !isIndirect) {
console.error(`Lazy factory failed:\n\n${factory}`); console.error(`makeLazy factory failed:\n\n${factory}`);
} }
} }