@nxtedition/deepstream.io-client-js 24.1.2 → 24.1.4
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
package/src/record/record.js
CHANGED
|
@@ -5,6 +5,7 @@ const messageParser = require('../message/message-parser')
|
|
|
5
5
|
const xuid = require('xuid')
|
|
6
6
|
const invariant = require('invariant')
|
|
7
7
|
const cloneDeep = require('lodash.clonedeep')
|
|
8
|
+
const timers = require('../utils/timers')
|
|
8
9
|
|
|
9
10
|
class Record {
|
|
10
11
|
static STATE = C.RECORD_STATE
|
|
@@ -185,17 +186,33 @@ class Record {
|
|
|
185
186
|
|
|
186
187
|
const signal = optionsOrNil?.signal
|
|
187
188
|
const state = stateOrNil ?? C.RECORD_STATE.SERVER
|
|
189
|
+
const timeout = optionsOrNil?.timeout ?? 2 * 60e3
|
|
188
190
|
|
|
189
191
|
if (!Number.isFinite(state) || state < 0) {
|
|
190
192
|
throw new Error('invalid argument: state')
|
|
191
193
|
}
|
|
192
194
|
|
|
193
|
-
await new Promise((resolve) => {
|
|
195
|
+
await new Promise((resolve, reject) => {
|
|
194
196
|
if (this._state >= state) {
|
|
195
197
|
resolve(null)
|
|
196
198
|
return
|
|
197
199
|
}
|
|
198
200
|
|
|
201
|
+
let timeoutHandle
|
|
202
|
+
|
|
203
|
+
if (timeout > 0) {
|
|
204
|
+
timeoutHandle = timers.setTimeout(() => {
|
|
205
|
+
const expected = C.RECORD_STATE_NAME[state]
|
|
206
|
+
const current = C.RECORD_STATE_NAME[this._state]
|
|
207
|
+
|
|
208
|
+
reject(
|
|
209
|
+
Object.assign(new Error(`timeout ${this.name} [${current}<${expected}]`), {
|
|
210
|
+
code: 'ETIMEDOUT',
|
|
211
|
+
})
|
|
212
|
+
)
|
|
213
|
+
}, timeout)
|
|
214
|
+
}
|
|
215
|
+
|
|
199
216
|
const onUpdate = () => {
|
|
200
217
|
if (this._state < state) {
|
|
201
218
|
return
|
|
@@ -204,6 +221,11 @@ class Record {
|
|
|
204
221
|
this.unref()
|
|
205
222
|
this.unsubscribe(onUpdate)
|
|
206
223
|
|
|
224
|
+
if (timeoutHandle) {
|
|
225
|
+
timers.clearTimeout(timeoutHandle)
|
|
226
|
+
timeoutHandle = null
|
|
227
|
+
}
|
|
228
|
+
|
|
207
229
|
resolve(null)
|
|
208
230
|
}
|
|
209
231
|
|
|
@@ -13,7 +13,7 @@ class Listener {
|
|
|
13
13
|
this._recursive = recursive
|
|
14
14
|
this._stringify = stringify || JSON.stringify
|
|
15
15
|
|
|
16
|
-
this._$onConnectionStateChange(
|
|
16
|
+
this._$onConnectionStateChange()
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
get connected() {
|
|
@@ -209,8 +209,8 @@ class Listener {
|
|
|
209
209
|
return true
|
|
210
210
|
}
|
|
211
211
|
|
|
212
|
-
_$onConnectionStateChange(
|
|
213
|
-
if (connected) {
|
|
212
|
+
_$onConnectionStateChange() {
|
|
213
|
+
if (this.connected) {
|
|
214
214
|
this._connection.sendMsg(this._topic, C.ACTIONS.LISTEN, [this._pattern])
|
|
215
215
|
} else {
|
|
216
216
|
this._reset()
|
|
@@ -38,7 +38,7 @@ class Listener {
|
|
|
38
38
|
this._connection = this._handler._connection
|
|
39
39
|
this._subscriptions = new Map()
|
|
40
40
|
|
|
41
|
-
this._$onConnectionStateChange(
|
|
41
|
+
this._$onConnectionStateChange()
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
get connected() {
|
|
@@ -90,8 +90,8 @@ class Listener {
|
|
|
90
90
|
next: (data) => {
|
|
91
91
|
if (data == null) {
|
|
92
92
|
this._connection.sendMsg(this._topic, C.ACTIONS.LISTEN_REJECT, [this._pattern, name])
|
|
93
|
+
this._subscriptions.delete(name)
|
|
93
94
|
subscription.unsubscribe()
|
|
94
|
-
this._subscriptions.set(name, null)
|
|
95
95
|
} else {
|
|
96
96
|
const version = `INF-${this._connection.hasher.h64ToString(data)}`
|
|
97
97
|
this._connection.sendMsg(this._topic, C.ACTIONS.UPDATE, [name, version, data])
|
|
@@ -105,27 +105,25 @@ class Listener {
|
|
|
105
105
|
this._subscriptions.set(name, subscription)
|
|
106
106
|
} else {
|
|
107
107
|
this._connection.sendMsg(this._topic, C.ACTIONS.LISTEN_REJECT, [this._pattern, name])
|
|
108
|
-
this._subscriptions.
|
|
108
|
+
this._subscriptions.delete(name)
|
|
109
109
|
}
|
|
110
110
|
} else if (message.action === C.ACTIONS.LISTEN_REJECT) {
|
|
111
|
-
if (!this._subscriptions.has(name)) {
|
|
112
|
-
this._error(name, 'invalid remove: listener missing')
|
|
113
|
-
return
|
|
114
|
-
}
|
|
115
|
-
|
|
116
111
|
const subscription = this._subscriptions.get(name)
|
|
117
112
|
|
|
118
|
-
subscription
|
|
119
|
-
|
|
120
|
-
|
|
113
|
+
if (subscription) {
|
|
114
|
+
this._subscriptions.delete(name)
|
|
115
|
+
subscription.unsubscribe()
|
|
116
|
+
} else {
|
|
117
|
+
this._error(name, 'invalid remove: listener missing')
|
|
118
|
+
}
|
|
121
119
|
} else {
|
|
122
120
|
return false
|
|
123
121
|
}
|
|
124
122
|
return true
|
|
125
123
|
}
|
|
126
124
|
|
|
127
|
-
_$onConnectionStateChange(
|
|
128
|
-
if (connected) {
|
|
125
|
+
_$onConnectionStateChange() {
|
|
126
|
+
if (this.connected) {
|
|
129
127
|
this._connection.sendMsg(this._topic, C.ACTIONS.LISTEN, [this._pattern, 'U'])
|
|
130
128
|
} else {
|
|
131
129
|
this._reset()
|