Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Support passing AbortSignal into request()
  • Loading branch information
aron committed Mar 26, 2025
commit f32e187ebcae9dff3f172f143dec70388fc1fcb1
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ declare module "replicate" {
headers?: object | Headers;
params?: object;
data?: object;
signal?: AbortSignal;
}
): Promise<Response>;

Expand Down
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ class Replicate {
* @param {object} [options.params] - Query parameters
* @param {object|Headers} [options.headers] - HTTP headers
* @param {object} [options.data] - Body parameters
* @param {AbortSignal} [options.signal] - AbortSignal to cancel the request
* @returns {Promise<Response>} - Resolves with the response object
* @throws {ApiError} If the request failed
*/
Expand All @@ -241,7 +242,7 @@ class Replicate {
);
}

const { method = "GET", params = {}, data } = options;
const { method = "GET", params = {}, data, signal } = options;

for (const [key, value] of Object.entries(params)) {
url.searchParams.append(key, value);
Expand Down Expand Up @@ -273,6 +274,7 @@ class Replicate {
method,
headers,
body,
signal,
};

const shouldRetry =
Expand Down