Skip to content

Commit 0d528ce

Browse files
committed
Fix for HN comments error-handling
1 parent 76e5777 commit 0d528ce

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

loadHnComments.ts

+11-9
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,17 @@ export default async function getCommentsCached(postName: string) {
1919
return data
2020
} else {
2121
if (!POST_COMMENTS_LOADING.get(postName) && (Date.now() - cached.timestamp > COMMENTS_CACHE_LIFETIME)) {
22-
try {
23-
// if comments are cached but expired, start updating them but return cached for now
24-
POST_COMMENTS_LOADING.set(postName, true)
25-
loadAndRender(postName)
26-
.then(data =>
27-
COMMENTS_CACHE.set(postName, { data, timestamp: Date.now() }))
28-
.finally(() => POST_COMMENTS_LOADING.set(postName, false))
29-
} catch {
30-
}
22+
// if comments are cached but expired, start updating them but return cached for now
23+
POST_COMMENTS_LOADING.set(postName, true)
24+
25+
void (async function () {
26+
try {
27+
const data = await loadAndRender(postName)
28+
COMMENTS_CACHE.set(postName, { data, timestamp: Date.now() })
29+
} finally {
30+
POST_COMMENTS_LOADING.set(postName, false)
31+
}
32+
})()
3133
}
3234

3335
return cached.data

0 commit comments

Comments
 (0)