@dashevo/dapi-client 4.1.0-rc.3 → 4.2.0-dev.1

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.
@@ -8,6 +8,8 @@ const EVENTS = {
8
8
  ERROR: 'error',
9
9
  };
10
10
 
11
+ const CLIENT_ALREADY_CLOSED_ERROR_MESSAGE = 'Client already closed - cannot .close()';
12
+
11
13
  /**
12
14
  * @typedef BlockHeadersReaderOptions
13
15
  * @property {number} [maxParallelStreams]
@@ -132,8 +134,9 @@ class BlockHeadersReader extends EventEmitter {
132
134
  * @param e
133
135
  */
134
136
  const rejectHeaders = async (e) => {
135
- // Don't use cancelStream there because it's going to unsubscribe from events
136
- stream.cancel();
137
+ // Cancel the transport only: the retry below needs the listeners, so
138
+ // this cannot go through cancelStream, which unsubscribes from events
139
+ this.cancelStreamTransport(stream);
137
140
  stream.retryOnError(e);
138
141
  };
139
142
 
@@ -294,9 +297,25 @@ class BlockHeadersReader extends EventEmitter {
294
297
  }
295
298
 
296
299
  // eslint-disable-next-line class-methods-use-this
300
+ /**
301
+ * Cancels the stream's transport, tolerating one the transport has already
302
+ * closed. Listeners are left in place for callers that keep using the stream.
303
+ * @param {ReconnectableStream} stream
304
+ */
305
+ // eslint-disable-next-line class-methods-use-this
306
+ cancelStreamTransport(stream) {
307
+ try {
308
+ stream.cancel();
309
+ } catch (e) {
310
+ if (e.message !== CLIENT_ALREADY_CLOSED_ERROR_MESSAGE) {
311
+ throw e;
312
+ }
313
+ }
314
+ }
315
+
297
316
  cancelStream(stream) {
298
317
  stream.removeAllListeners();
299
- stream.cancel();
318
+ this.cancelStreamTransport(stream);
300
319
  }
301
320
  }
302
321
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dashevo/dapi-client",
3
- "version": "4.1.0-rc.3",
3
+ "version": "4.2.0-dev.1",
4
4
  "description": "Client library used to access Dash DAPI endpoints",
5
5
  "main": "lib/index.js",
6
6
  "contributors": [
@@ -26,11 +26,11 @@
26
26
  }
27
27
  ],
28
28
  "dependencies": {
29
- "@dashevo/dapi-grpc": "4.1.0-rc.3",
30
- "@dashevo/dash-spv": "5.1.0-rc.3",
29
+ "@dashevo/dapi-grpc": "4.2.0-dev.1",
30
+ "@dashevo/dash-spv": "5.2.0-dev.1",
31
31
  "@dashevo/dashcore-lib": "~0.22.0",
32
- "@dashevo/grpc-common": "4.1.0-rc.3",
33
- "@dashevo/wasm-dpp": "4.1.0-rc.3",
32
+ "@dashevo/grpc-common": "4.2.0-dev.1",
33
+ "@dashevo/wasm-dpp": "4.2.0-dev.1",
34
34
  "cbor": "^8.0.0",
35
35
  "google-protobuf": "^3.12.2",
36
36
  "undici": "^6.0.0",