16
16
17
17
import IRESTClient , { ErrorResponseHandler , ResponseHandler } from "./IRESTClient" ;
18
18
import ClientResponse from "./ClientResponse" ;
19
- import fetch , { BodyInit , RequestCredentials , Response } from ' node-fetch' ;
19
+ import fetch , { BodyInit , RequestCredentials , Response } from " node-fetch" ;
20
20
import { URLSearchParams } from "url" ;
21
21
22
22
/**
@@ -33,6 +33,7 @@ export default class DefaultRESTClient<RT, ERT> implements IRESTClient<RT, ERT>
33
33
public credentials : RequestCredentials ;
34
34
public responseHandler : ResponseHandler < RT > = DefaultRESTClient . JSONResponseHandler ;
35
35
public errorResponseHandler : ErrorResponseHandler < ERT > = DefaultRESTClient . ErrorJSONResponseHandler ;
36
+ public abortSignal : AbortSignal = undefined ;
36
37
37
38
constructor ( public host : string ) {
38
39
}
@@ -202,6 +203,15 @@ export default class DefaultRESTClient<RT, ERT> implements IRESTClient<RT, ERT>
202
203
return this ;
203
204
}
204
205
206
+ /**
207
+ * Sets the AbortSignal for the request.
208
+ * @param signal The AbortSignal to use to abort the request.
209
+ */
210
+ withAbortSignal ( signal : AbortSignal ) : DefaultRESTClient < RT , ERT > {
211
+ this . abortSignal = signal ;
212
+ return this ;
213
+ }
214
+
205
215
/**
206
216
* Run the request and return a promise. This promise will resolve if the request is successful
207
217
* and reject otherwise.
@@ -219,8 +229,7 @@ export default class DefaultRESTClient<RT, ERT> implements IRESTClient<RT, ERT>
219
229
body : this . body as BodyInit ,
220
230
// @ts -ignore (Credentials are not supported on NodeJS)
221
231
credentials : this . credentials ,
222
- // 60-second timeout expressed in ms
223
- timeout : 60000 ,
232
+ signal : this . abortSignal ,
224
233
} ,
225
234
) ;
226
235
0 commit comments