Files
CHOMPStation2/tgui/packages/tgui_ch/http.ts
2023-06-19 18:44:18 +02:00

17 lines
397 B
TypeScript

/**
* An equivalent to `fetch`, except will automatically retry.
*/
export const fetchRetry = (
url: string,
options?: RequestInit,
retryTimer: number = 1000
): Promise<Response> => {
return fetch(url, options).catch(() => {
return new Promise((resolve) => {
setTimeout(() => {
fetchRetry(url, options, retryTimer).then(resolve);
}, retryTimer);
});
});
};