You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: index.js
+21-3Lines changed: 21 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -85,6 +85,7 @@ class Replicate {
85
85
* @param {number} [options.wait.max_attempts] - Maximum number of polling attempts. Defaults to no limit
86
86
* @param {string} [options.webhook] - An HTTPS URL for receiving a webhook when the prediction has new output
87
87
* @param {string[]} [options.webhook_events_filter] - You can change which events trigger webhook requests by specifying webhook events (`start`|`output`|`logs`|`completed`)
88
+
* @param {AbortSignal} [options.signal] - AbortSignal to cancel the prediction
88
89
* @throws {Error} If the prediction failed
89
90
* @returns {Promise<object>} - Resolves with the output of running the model
90
91
*/
@@ -116,7 +117,16 @@ class Replicate {
116
117
version,
117
118
});
118
119
119
-
prediction=awaitthis.wait(prediction,wait||{});
120
+
const{ signal }=options;
121
+
122
+
prediction=awaitthis.wait(prediction,wait||{},async({ id })=>{
* @param {number} [options.interval] - Polling interval in milliseconds. Defaults to 250
221
235
* @param {number} [options.max_attempts] - Maximum number of polling attempts. Defaults to no limit
236
+
* @param {Function} [stop] - Async callback function that is called after each polling attempt. Receives the prediction object as an argument. Return false to cancel polling.
222
237
* @throws {Error} If the prediction doesn't complete within the maximum number of attempts
223
238
* @throws {Error} If the prediction failed
224
239
* @returns {Promise<object>} Resolves with the completed prediction object
0 commit comments