diff --git a/src/DefaultRESTClient.ts b/src/DefaultRESTClient.ts index b64381f..addc85b 100644 --- a/src/DefaultRESTClient.ts +++ b/src/DefaultRESTClient.ts @@ -16,7 +16,7 @@ import IRESTClient, { ErrorResponseHandler, ResponseHandler } from "./IRESTClient"; import ClientResponse from "./ClientResponse"; -import fetch, { BodyInit, RequestCredentials, Response } from 'node-fetch'; +import fetch, { BodyInit, RequestCredentials, Response } from "node-fetch"; import { URLSearchParams } from "url"; /** @@ -33,6 +33,7 @@ export default class DefaultRESTClient implements IRESTClient public credentials: RequestCredentials; public responseHandler: ResponseHandler = DefaultRESTClient.JSONResponseHandler; public errorResponseHandler: ErrorResponseHandler = DefaultRESTClient.ErrorJSONResponseHandler; + public abortSignal: AbortSignal = undefined; constructor(public host: string) { } @@ -202,6 +203,15 @@ export default class DefaultRESTClient implements IRESTClient return this; } + /** + * Sets the AbortSignal for the request. + * @param signal The AbortSignal to use to abort the request. + */ + withAbortSignal(signal: AbortSignal): DefaultRESTClient { + this.abortSignal = signal; + return this; + } + /** * Run the request and return a promise. This promise will resolve if the request is successful * and reject otherwise. @@ -219,6 +229,7 @@ export default class DefaultRESTClient implements IRESTClient body: this.body as BodyInit, // @ts-ignore (Credentials are not supported on NodeJS) credentials: this.credentials, + signal: this.abortSignal, }, ); diff --git a/tsconfig.json b/tsconfig.json index a171172..5f3c4e7 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,7 +5,8 @@ "declaration": true, "sourceMap": true, "lib": [ - "es2015" + "es2015", + "dom" ], "outDir": "build", "types": [