Remove abortAfterTimeout
It's fundamentally flawed because it doesn't support easy cancellation of the timeout.
This commit is contained in:
parent
cfd3464238
commit
53f55b8edf
3 changed files with 0 additions and 28 deletions
|
|
@ -48,8 +48,6 @@ export type RequestOptions = {
|
|||
|
||||
/**
|
||||
* Can be used to cancel an in-flight request. This will cause an AbortError to be raised from request().
|
||||
*
|
||||
* Use abortAfterTimeout() to easily implement timeouts using this signal.
|
||||
*/
|
||||
signal?: AbortSignal;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,15 +0,0 @@
|
|||
import { abortAfterTimeout } from "./utils.js";
|
||||
|
||||
describe("abortAfterTimeout", () => {
|
||||
it("should abort after timeout", () => {
|
||||
const signal = abortAfterTimeout(0);
|
||||
expect(signal.aborted).toBe(false);
|
||||
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
expect(signal.aborted).toBe(true);
|
||||
resolve(true);
|
||||
}, 0);
|
||||
});
|
||||
});
|
||||
});
|
||||
11
src/utils.ts
11
src/utils.ts
|
|
@ -1,11 +0,0 @@
|
|||
/**
|
||||
* Returns an AbortSignal that will enter aborted state after `timeoutMs` milliseconds.
|
||||
*/
|
||||
export function abortAfterTimeout(timeoutMs: number): AbortSignal {
|
||||
const controller = new AbortController();
|
||||
setTimeout(() => {
|
||||
controller.abort("Timeout exceeded");
|
||||
}, timeoutMs);
|
||||
|
||||
return controller.signal;
|
||||
}
|
||||
Loading…
Reference in a new issue