@robosystems/client 2.5.1 → 2.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -132,12 +132,30 @@ class OperatorClient {
|
|
|
132
132
|
}
|
|
133
133
|
return new Promise((resolve, reject) => {
|
|
134
134
|
let result = null;
|
|
135
|
+
let settled = false;
|
|
135
136
|
const finish = () => {
|
|
137
|
+
settled = true;
|
|
136
138
|
sseClient.close();
|
|
137
139
|
if (this.sseClient === sseClient) {
|
|
138
140
|
this.sseClient = undefined;
|
|
139
141
|
}
|
|
140
142
|
};
|
|
143
|
+
// The stream closed before a terminal event: a reconnect that failed
|
|
144
|
+
// before opening, retries exhausted, or this client being closed. The
|
|
145
|
+
// SSE client clears its listeners as it closes, so without this the
|
|
146
|
+
// promise would never settle. The run finishes whether or not anyone
|
|
147
|
+
// watches, so a dropped stream follows it over `/status` instead.
|
|
148
|
+
sseClient.on('closed', () => {
|
|
149
|
+
if (settled)
|
|
150
|
+
return;
|
|
151
|
+
settled = true;
|
|
152
|
+
if (this.sseClient !== sseClient) {
|
|
153
|
+
reject(new OperatorRunError('Operator client closed', 'cancelled', []));
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
this.sseClient = undefined;
|
|
157
|
+
this.pollForCompletion(operationId, options, new Error('the stream closed before the run finished')).then(resolve, reject);
|
|
158
|
+
});
|
|
141
159
|
// Listen for progress events
|
|
142
160
|
sseClient.on(SSEClient_1.EventType.OPERATION_PROGRESS, (data) => {
|
|
143
161
|
options.onProgress?.(data.message, data.progress_percentage);
|
|
@@ -247,8 +265,11 @@ class OperatorClient {
|
|
|
247
265
|
*/
|
|
248
266
|
close() {
|
|
249
267
|
if (this.sseClient) {
|
|
250
|
-
this
|
|
268
|
+
// Detach first: a run watching this stream reads the detach as a
|
|
269
|
+
// deliberate close and rejects instead of polling on.
|
|
270
|
+
const sseClient = this.sseClient;
|
|
251
271
|
this.sseClient = undefined;
|
|
272
|
+
sseClient.close();
|
|
252
273
|
}
|
|
253
274
|
}
|
|
254
275
|
}
|
|
@@ -228,14 +228,36 @@ export class OperatorClient {
|
|
|
228
228
|
|
|
229
229
|
return new Promise((resolve, reject) => {
|
|
230
230
|
let result: OperatorResult | null = null
|
|
231
|
+
let settled = false
|
|
231
232
|
|
|
232
233
|
const finish = () => {
|
|
234
|
+
settled = true
|
|
233
235
|
sseClient.close()
|
|
234
236
|
if (this.sseClient === sseClient) {
|
|
235
237
|
this.sseClient = undefined
|
|
236
238
|
}
|
|
237
239
|
}
|
|
238
240
|
|
|
241
|
+
// The stream closed before a terminal event: a reconnect that failed
|
|
242
|
+
// before opening, retries exhausted, or this client being closed. The
|
|
243
|
+
// SSE client clears its listeners as it closes, so without this the
|
|
244
|
+
// promise would never settle. The run finishes whether or not anyone
|
|
245
|
+
// watches, so a dropped stream follows it over `/status` instead.
|
|
246
|
+
sseClient.on('closed', () => {
|
|
247
|
+
if (settled) return
|
|
248
|
+
settled = true
|
|
249
|
+
if (this.sseClient !== sseClient) {
|
|
250
|
+
reject(new OperatorRunError('Operator client closed', 'cancelled', []))
|
|
251
|
+
return
|
|
252
|
+
}
|
|
253
|
+
this.sseClient = undefined
|
|
254
|
+
this.pollForCompletion(
|
|
255
|
+
operationId,
|
|
256
|
+
options,
|
|
257
|
+
new Error('the stream closed before the run finished')
|
|
258
|
+
).then(resolve, reject)
|
|
259
|
+
})
|
|
260
|
+
|
|
239
261
|
// Listen for progress events
|
|
240
262
|
sseClient.on(EventType.OPERATION_PROGRESS, (data) => {
|
|
241
263
|
options.onProgress?.(data.message, data.progress_percentage)
|
|
@@ -387,8 +409,11 @@ export class OperatorClient {
|
|
|
387
409
|
*/
|
|
388
410
|
close(): void {
|
|
389
411
|
if (this.sseClient) {
|
|
390
|
-
this
|
|
412
|
+
// Detach first: a run watching this stream reads the detach as a
|
|
413
|
+
// deliberate close and rejects instead of polling on.
|
|
414
|
+
const sseClient = this.sseClient
|
|
391
415
|
this.sseClient = undefined
|
|
416
|
+
sseClient.close()
|
|
392
417
|
}
|
|
393
418
|
}
|
|
394
419
|
}
|