Files
blitzkit/src/core/blitzkrieg/patientFetch.ts
T

14 lines
399 B
TypeScript
Raw Normal View History

2023-11-13 13:15:55 -06:00
export async function patientFetch(url: string, timeout = 1000) {
2023-11-07 18:58:19 -06:00
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;
}