Skip to content

Commit 4a10c04

Browse files
committed
Support passing AbortSignal into request()
1 parent 0b7c8eb commit 4a10c04

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ declare module "replicate" {
183183
headers?: object | Headers;
184184
params?: object;
185185
data?: object;
186+
signal?: AbortSignal;
186187
}
187188
): Promise<Response>;
188189

index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ class Replicate {
225225
* @param {object} [options.params] - Query parameters
226226
* @param {object|Headers} [options.headers] - HTTP headers
227227
* @param {object} [options.data] - Body parameters
228+
* @param {AbortSignal} [options.signal] - AbortSignal to cancel the request
228229
* @returns {Promise<Response>} - Resolves with the response object
229230
* @throws {ApiError} If the request failed
230231
*/
@@ -241,7 +242,7 @@ class Replicate {
241242
);
242243
}
243244

244-
const { method = "GET", params = {}, data } = options;
245+
const { method = "GET", params = {}, data, signal } = options;
245246

246247
for (const [key, value] of Object.entries(params)) {
247248
url.searchParams.append(key, value);
@@ -273,6 +274,7 @@ class Replicate {
273274
method,
274275
headers,
275276
body,
277+
signal,
276278
};
277279

278280
const shouldRetry =

0 commit comments

Comments
 (0)