Skip to content

Commit

Permalink
cannot reassign const
Browse files Browse the repository at this point in the history
  • Loading branch information
acdibble committed Jun 19, 2024
1 parent f4e8baa commit 65df0ed
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion bouncer/shared/utils/substrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ const getCachedDisposable = <T extends AsyncDisposable, F extends (...args: any[
let disposablePromise = cache.get(cacheKey);

if (!disposablePromise) {
// we can't call await here because if this function is called multiple times
// before the promise resolves, we would create multiple instances of the same
// disposable. Instead, we cache the promise and return it immediately.
disposablePromise = factory(...args);
cache.set(cacheKey, disposablePromise);
console.log('creating disposable', name, cacheKey);
Expand All @@ -45,7 +48,7 @@ const getCachedDisposable = <T extends AsyncDisposable, F extends (...args: any[
) as unknown as () => Promise<void>;

dispose.call(target).catch(() => null);
disposable = undefined;
cache.delete(cacheKey);
} catch (error) {
console.error('Failed to dispose', name, cacheKey, error);
}
Expand Down

0 comments on commit 65df0ed

Please sign in to comment.