update deno commons mod
This commit is contained in:
@@ -795,6 +795,9 @@ export class ProcessBar {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Use {@link fetchDataWithTimeout} instead.
|
||||||
|
*/
|
||||||
export async function fetchWithTimeout(
|
export async function fetchWithTimeout(
|
||||||
input: URL | Request | string,
|
input: URL | Request | string,
|
||||||
timeout?: number,
|
timeout?: number,
|
||||||
@@ -815,6 +818,31 @@ export async function fetchWithTimeout(
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type RequestInitWithTimeout = RequestInit & {
|
||||||
|
timeoutMillis?: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export async function fetchDataWithTimeout(
|
||||||
|
input: URL | Request | string,
|
||||||
|
init: RequestInitWithTimeout = {},
|
||||||
|
): Promise<Response> {
|
||||||
|
const timeout = init.timeoutMillis ?? 10000;
|
||||||
|
const abortController = new AbortController();
|
||||||
|
const timeoutHandler = setTimeout(() => {
|
||||||
|
abortController.abort(
|
||||||
|
`Fetch '${input}' timeout: ${timeout} ms`,
|
||||||
|
);
|
||||||
|
}, timeout);
|
||||||
|
try {
|
||||||
|
return await fetch(input, {
|
||||||
|
...init,
|
||||||
|
signal: abortController.signal,
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
clearTimeout(timeoutHandler);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function getCurrentScriptFile(): string {
|
export function getCurrentScriptFile(): string {
|
||||||
return fromFileUrl(import.meta.url);
|
return fromFileUrl(import.meta.url);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user