mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 11:39:50 +02:00
fix: no double fetch and caching
This commit is contained in:
1 parent
6600bba58c
commit
fbde9ec64f
4 files changed
+243
-120
No files matched your search
@@ -0,0 +1,14 @@
|
||||
export async function patientFetch(url: string, timeout = 1 * 60 * 1000) {
|
||||
let patientResponse: Response;
|
||||
|
||||
while (patientResponse! === undefined) {
|
||||
try {
|
||||
patientResponse = await fetch(url);
|
||||
} catch (error) {
|
||||
console.warn(`Failed to fetch ${url}; retrying in ${timeout}ms...`);
|
||||
await new Promise((resolve) => setTimeout(resolve, timeout));
|
||||
}
|
||||
}
|
||||
|
||||
return patientResponse;
|
||||
}
|
||||
Reference in new issue
Block a user