Skip to content

Commit 167a70a

Browse files
authored
Merge pull request #133 from wolfpackthatcodes/feature/timeout
Add support for requests to timeout
2 parents 5dbce0d + 042ba1e commit 167a70a

File tree

8 files changed

+486
-156
lines changed

8 files changed

+486
-156
lines changed

code/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
"eslint-import-resolver-typescript": "^3.6.1",
6363
"eslint-plugin-import": "^2.29.1",
6464
"eslint-plugin-prettier": "^5.1.3",
65+
"msw": "^2.2.0",
6566
"prettier": "^3.2.5",
6667
"typescript": "^5.3.3",
6768
"vite": "^5.1.1",

code/src/http/httpClient.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,19 @@ export default class HttpClient {
475475
}
476476
}
477477

478+
/**
479+
* Specify the timeout (in milliseconds) for the pending request.
480+
*
481+
* @param {number} milliseconds
482+
*
483+
* @returns {this}
484+
*/
485+
public timeout(milliseconds: number): this {
486+
this.withOption('signal', AbortSignal.timeout(milliseconds));
487+
488+
return this;
489+
}
490+
478491
/**
479492
* Specify the basic authentication username and password for the request.
480493
*

code/src/http/types/options.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ export type Options = {
44
body?: FormData | string | URLSearchParams;
55
credentials?: RequestCredentials;
66
headers?: Headers;
7+
signal?: AbortSignal;
78
[key: string]: RequestOptions;
89
};
File renamed without changes.

0 commit comments

Comments
 (0)