From 89c7f563a3e41ab2efda37726f6ad99f30d9ec41 Mon Sep 17 00:00:00 2001 From: mat Date: Wed, 1 Jun 2022 18:49:59 -0500 Subject: Fix hanging on errors in withCache --- src/util.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/util.ts b/src/util.ts index 9af95c7..f50118b 100644 --- a/src/util.ts +++ b/src/util.ts @@ -132,7 +132,14 @@ export async function withCache(key: string, ttl: number | ((arg: T) => Date) ...(caches.get(key) ?? { data: undefined, nextUpdate: new Date(0) }), isFetching: true, }) - const data = await task() + const data = await task().catch(e => { + console.error(e) + caches.set(key, { + ...(caches.get(key) ?? { data: undefined, nextUpdate: new Date(0) }), + isFetching: false, + }) + return undefined + }) caches.set(key, { ...caches.get(key)!, isFetching: false, -- cgit