@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 +1 -1
- package/src/record/record-handler.js +84 -57
package/package.json
CHANGED
|
@@ -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
|
|
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
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
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
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
const
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
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) {
|