Skip to content

Commit

Permalink
fix: improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
exKAZUu committed Dec 19, 2024
1 parent b400068 commit 4ee9a51
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions src/memoize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,22 @@ export function memoizeFactory({
}
}
cache.set(key, [result, now]);
try {
if (result instanceof Promise) {
void (async () => {
const promise = persistCache?.(key, now, await result) as unknown;
if (result instanceof Promise) {
void (async () => {
try {
const promise = persistCache?.(key, now, result) as unknown;
if (promise instanceof Promise) promise.catch(noop);
});
} else {
} catch {
// do nothing.
}
});
} else {
try {
const promise = persistCache?.(key, now, result) as unknown;
if (promise instanceof Promise) promise.catch(noop);
} catch {
// do nothing.
}
} catch {
// do nothing.
}

console.log(`Exiting getter ${String(context.name)}.`);
Expand Down Expand Up @@ -189,18 +193,22 @@ export function memoizeFactory({
}
}
cache.set(key, [result, now]);
try {
if (result instanceof Promise) {
void (async () => {
const promise = persistCache?.(key, now, await result) as unknown;
if (result instanceof Promise) {
void (async () => {
try {
const promise = persistCache?.(key, now, result) as unknown;
if (promise instanceof Promise) promise.catch(noop);
});
} else {
} catch {
// do nothing.
}
});
} else {
try {
const promise = persistCache?.(key, now, result) as unknown;
if (promise instanceof Promise) promise.catch(noop);
} catch {
// do nothing.
}
} catch {
// do nothing.
}

console.log(`Exiting ${context ? `method ${String(context.name)}` : 'function'}.`);
Expand Down

0 comments on commit 4ee9a51

Please sign in to comment.