@nxtedition/deepstream.io-client-js 24.0.13 → 24.0.14

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/deepstream.io-client-js",
3
- "version": "24.0.13",
3
+ "version": "24.0.14",
4
4
  "description": "the javascript client for deepstream.io",
5
5
  "homepage": "http://deepstream.io",
6
6
  "bugs": {
@@ -226,67 +226,94 @@ class RecordHandler {
226
226
  }
227
227
  }
228
228
 
229
- async sync() {
229
+ async sync({ timeout, signal }) {
230
230
  // TODO (fix): Sync pending? What about VOID state?
231
231
 
232
- let patchingTimeout
233
- await Promise.race([
234
- Promise.all(
235
- [...this._patching.values()].map(
236
- (callbacks) => new Promise((resolve) => callbacks.push(resolve))
237
- )
238
- ),
239
- new Promise((resolve) => {
240
- patchingTimeout = timers.setTimeout(() => {
241
- this._client._$onError(
242
- C.TOPIC.RECORD,
243
- C.EVENT.TIMEOUT,
244
- new Error('sync patching timeout')
245
- )
246
- resolve(null)
247
- }, 2 * 60e3)
248
- }),
249
- ]).finally(() => {
250
- timers.clearTimeout(patchingTimeout)
251
- })
232
+ let onAbort
252
233
 
253
- let updatingTimeout
254
- await Promise.race([
255
- Promise.all(
256
- [...this._updating.values()].map(
257
- (callbacks) => new Promise((resolve) => callbacks.push(resolve))
258
- )
259
- ),
260
- new Promise((resolve) => {
261
- updatingTimeout = timers.setTimeout(() => {
262
- this._client._$onError(
263
- C.TOPIC.RECORD,
264
- C.EVENT.TIMEOUT,
265
- new Error('sync updating timeout')
266
- )
267
- resolve(null)
268
- }, 2 * 60e3)
269
- }),
270
- ]).finally(() => {
271
- timers.clearTimeout(updatingTimeout)
272
- })
234
+ const signalPromise = signal
235
+ ? new Promise((resolve, reject) => {
236
+ onAbort = () => {
237
+ reject(signal.reason ?? new utils.AbortError())
238
+ }
239
+ signal.addEventListener('abort', onAbort)
240
+ })
241
+ : null
242
+ signalPromise?.catch(() => {})
273
243
 
274
- let serverTimeout
275
- await Promise.race([
276
- await new Promise((resolve) => {
277
- const token = xuid()
278
- this._syncEmitter.once(token, resolve)
279
- this._connection.sendMsg(C.TOPIC.RECORD, C.ACTIONS.SYNC, [token])
280
- }),
281
- new Promise((resolve) => {
282
- serverTimeout = timers.setTimeout(() => {
283
- this._client._$onError(C.TOPIC.RECORD, C.EVENT.TIMEOUT, new Error('sync server timeout'))
284
- resolve(null)
285
- }, 2 * 60e3)
286
- }),
287
- ]).finally(() => {
288
- timers.clearTimeout(serverTimeout)
289
- })
244
+ try {
245
+ if (this._patching.size) {
246
+ let patchingTimeout
247
+ const patching = [...this._patching.values()]
248
+ await Promise.race([
249
+ Promise.all(
250
+ patching.map((callbacks) => new Promise((resolve) => callbacks.push(resolve)))
251
+ ),
252
+ new Promise((resolve) => {
253
+ patchingTimeout = timers.setTimeout(() => {
254
+ this._client._$onError(
255
+ C.TOPIC.RECORD,
256
+ C.EVENT.TIMEOUT,
257
+ Object.assign(new Error('sync patching timeout'), { data: { patching, timeout } })
258
+ )
259
+ resolve(null)
260
+ }, timeout ?? 10 * 60e3)
261
+ }),
262
+ signalPromise,
263
+ ]).finally(() => {
264
+ timers.clearTimeout(patchingTimeout)
265
+ })
266
+ }
267
+
268
+ if (this._updating.size) {
269
+ let updatingTimeout
270
+ const updating = [...this._updating.values()]
271
+ await Promise.race([
272
+ Promise.all(
273
+ updating.map((callbacks) => new Promise((resolve) => callbacks.push(resolve)))
274
+ ),
275
+ new Promise((resolve) => {
276
+ updatingTimeout = timers.setTimeout(() => {
277
+ this._client._$onError(
278
+ C.TOPIC.RECORD,
279
+ C.EVENT.TIMEOUT,
280
+ Object.assign(new Error('sync updating timeout'), { data: { updating, timeout } })
281
+ )
282
+ resolve(null)
283
+ }, timeout ?? 10 * 60e3)
284
+ }),
285
+ signalPromise,
286
+ ]).finally(() => {
287
+ timers.clearTimeout(updatingTimeout)
288
+ })
289
+ }
290
+
291
+ let serverTimeout
292
+ const token = xuid()
293
+ await Promise.race([
294
+ await new Promise((resolve) => {
295
+ this._syncEmitter.once(token, resolve)
296
+ this._connection.sendMsg(C.TOPIC.RECORD, C.ACTIONS.SYNC, [token])
297
+ }),
298
+ new Promise((resolve) => {
299
+ serverTimeout = timers.setTimeout(() => {
300
+ this._client._$onError(
301
+ C.TOPIC.RECORD,
302
+ C.EVENT.TIMEOUT,
303
+ Object.assign(new Error('sync server timeout'), { data: { token, timeout } })
304
+ )
305
+ resolve(null)
306
+ }, timeout ?? 10 * 60e3)
307
+ }),
308
+ signalPromise,
309
+ ]).finally(() => {
310
+ timers.clearTimeout(serverTimeout)
311
+ })
312
+ } finally {
313
+ if (onAbort) {
314
+ signal?.removeEventListener('abort', onAbort)
315
+ }
316
+ }
290
317
  }
291
318
 
292
319
  set(name, ...args) {