@nxtedition/deepstream.io-client-js 24.1.2 → 24.1.3

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.1.2",
3
+ "version": "24.1.3",
4
4
  "description": "the javascript client for deepstream.io",
5
5
  "homepage": "http://deepstream.io",
6
6
  "bugs": {
@@ -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