@nxtedition/deepstream.io-client-js 24.0.6 → 24.0.8
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 +82 -13
package/package.json
CHANGED
|
@@ -63,6 +63,8 @@ class RecordHandler {
|
|
|
63
63
|
this._records = new Map()
|
|
64
64
|
this._listeners = new Map()
|
|
65
65
|
this._pruning = new Set()
|
|
66
|
+
this._patching = new Map()
|
|
67
|
+
this._updating = new Map()
|
|
66
68
|
|
|
67
69
|
this._connected = 0
|
|
68
70
|
this._stats = {
|
|
@@ -124,16 +126,30 @@ class RecordHandler {
|
|
|
124
126
|
_onUpdating(rec, value) {
|
|
125
127
|
if (value) {
|
|
126
128
|
this._stats.updating += 1
|
|
129
|
+
this._updating.set(rec, [])
|
|
127
130
|
} else {
|
|
128
131
|
this._stats.updating -= 1
|
|
132
|
+
|
|
133
|
+
const callbacks = this._updating.get(rec)
|
|
134
|
+
this._updating.delete(rec)
|
|
135
|
+
for (const callback of callbacks) {
|
|
136
|
+
callback()
|
|
137
|
+
}
|
|
129
138
|
}
|
|
130
139
|
}
|
|
131
140
|
|
|
132
141
|
_onPatching(rec, value) {
|
|
133
142
|
if (value) {
|
|
134
143
|
this._stats.patching += 1
|
|
144
|
+
this._patching.set(rec, [])
|
|
135
145
|
} else {
|
|
136
146
|
this._stats.patching -= 1
|
|
147
|
+
|
|
148
|
+
const callbacks = this._patching.get(rec)
|
|
149
|
+
this._patching.delete(rec)
|
|
150
|
+
for (const callback of callbacks) {
|
|
151
|
+
callback()
|
|
152
|
+
}
|
|
137
153
|
}
|
|
138
154
|
}
|
|
139
155
|
|
|
@@ -202,13 +218,66 @@ class RecordHandler {
|
|
|
202
218
|
}
|
|
203
219
|
}
|
|
204
220
|
|
|
205
|
-
sync() {
|
|
206
|
-
// TODO (fix): Sync
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
221
|
+
async sync() {
|
|
222
|
+
// TODO (fix): Sync pending? What about VOID state?
|
|
223
|
+
|
|
224
|
+
let patchingTimeout
|
|
225
|
+
await Promise.race([
|
|
226
|
+
Promise.all(
|
|
227
|
+
[...this._patching.values()].map(
|
|
228
|
+
(callbacks) => new Promise((resolve) => callbacks.push(resolve))
|
|
229
|
+
)
|
|
230
|
+
),
|
|
231
|
+
new Promise((resolve) => {
|
|
232
|
+
patchingTimeout = timers.setTimeout(() => {
|
|
233
|
+
this._client._$onError(
|
|
234
|
+
C.TOPIC.RECORD,
|
|
235
|
+
C.EVENT.TIMEOUT,
|
|
236
|
+
new Error('sync patching timeout')
|
|
237
|
+
)
|
|
238
|
+
resolve(null)
|
|
239
|
+
}, 2 * 60e3)
|
|
240
|
+
}),
|
|
241
|
+
]).finally(() => {
|
|
242
|
+
timers.clearTimeout(patchingTimeout)
|
|
243
|
+
})
|
|
244
|
+
|
|
245
|
+
let updatingTimeout
|
|
246
|
+
await Promise.race([
|
|
247
|
+
Promise.all(
|
|
248
|
+
[...this._updating.values()].map(
|
|
249
|
+
(callbacks) => new Promise((resolve) => callbacks.push(resolve))
|
|
250
|
+
)
|
|
251
|
+
),
|
|
252
|
+
new Promise((resolve) => {
|
|
253
|
+
updatingTimeout = timers.setTimeout(() => {
|
|
254
|
+
this._client._$onError(
|
|
255
|
+
C.TOPIC.RECORD,
|
|
256
|
+
C.EVENT.TIMEOUT,
|
|
257
|
+
new Error('sync updating timeout')
|
|
258
|
+
)
|
|
259
|
+
resolve(null)
|
|
260
|
+
}, 2 * 60e3)
|
|
261
|
+
}),
|
|
262
|
+
]).finally(() => {
|
|
263
|
+
timers.clearTimeout(updatingTimeout)
|
|
264
|
+
})
|
|
265
|
+
|
|
266
|
+
let serverTimeout
|
|
267
|
+
await Promise.race([
|
|
268
|
+
await new Promise((resolve) => {
|
|
269
|
+
const token = xuid()
|
|
270
|
+
this._syncEmitter.once(token, resolve)
|
|
271
|
+
this._connection.sendMsg(C.TOPIC.RECORD, C.ACTIONS.SYNC, [token])
|
|
272
|
+
}),
|
|
273
|
+
new Promise((resolve) => {
|
|
274
|
+
serverTimeout = timers.setTimeout(() => {
|
|
275
|
+
this._client._$onError(C.TOPIC.RECORD, C.EVENT.TIMEOUT, new Error('sync server timeout'))
|
|
276
|
+
resolve(null)
|
|
277
|
+
}, 2 * 60e3)
|
|
278
|
+
}),
|
|
279
|
+
]).finally(() => {
|
|
280
|
+
timers.clearTimeout(serverTimeout)
|
|
212
281
|
})
|
|
213
282
|
}
|
|
214
283
|
|
|
@@ -307,23 +376,23 @@ class RecordHandler {
|
|
|
307
376
|
if (idx < args.length && (args[idx] == null || typeof args[idx] === 'object')) {
|
|
308
377
|
const options = args[idx++] || {}
|
|
309
378
|
|
|
310
|
-
if (options.signal
|
|
379
|
+
if (options.signal !== undefined) {
|
|
311
380
|
signal = options.signal
|
|
312
381
|
}
|
|
313
382
|
|
|
314
|
-
if (options.timeout
|
|
383
|
+
if (options.timeout !== undefined) {
|
|
315
384
|
timeout = options.timeout
|
|
316
385
|
}
|
|
317
386
|
|
|
318
|
-
if (options.path
|
|
387
|
+
if (options.path !== undefined) {
|
|
319
388
|
path = options.path
|
|
320
389
|
}
|
|
321
390
|
|
|
322
|
-
if (options.state
|
|
391
|
+
if (options.state !== undefined) {
|
|
323
392
|
state = options.state
|
|
324
393
|
}
|
|
325
394
|
|
|
326
|
-
if (options.dataOnly
|
|
395
|
+
if (options.dataOnly !== undefined) {
|
|
327
396
|
dataOnly = options.dataOnly
|
|
328
397
|
}
|
|
329
398
|
}
|
|
@@ -366,7 +435,7 @@ class RecordHandler {
|
|
|
366
435
|
|
|
367
436
|
const record = (subscription.record = this.getRecord(name).subscribe(onUpdate, subscription))
|
|
368
437
|
|
|
369
|
-
if (timeout && state && record.state < state) {
|
|
438
|
+
if (timeout > 0 && state && record.state < state) {
|
|
370
439
|
// TODO (perf): Avoid Timer allocation.
|
|
371
440
|
subscription.timeout = timers.setTimeout(onTimeout, timeout, subscription)
|
|
372
441
|
}
|