mirror of
https://github.com/feeddeck/feeddeck.git
synced 2026-05-26 13:30:16 -05:00
16 lines
478 B
TypeScript
16 lines
478 B
TypeScript
/**
|
|
* `fetchWithTimeout` is a wrapper around `fetch` that adds a timeout. If the request takes longer than the timeout, the
|
|
* request will be aborted.
|
|
*/
|
|
export const fetchWithTimeout = async (
|
|
url: string,
|
|
options: RequestInit,
|
|
timeout: number,
|
|
) => {
|
|
const controller = new AbortController();
|
|
const id = setTimeout(() => controller.abort(), timeout);
|
|
const res = await fetch(url, { ...options, signal: controller.signal });
|
|
clearTimeout(id);
|
|
return res;
|
|
};
|