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