http-air 1.3.4 → 1.3.5

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.
@@ -6,6 +6,7 @@ export declare class EventsClient {
6
6
  private response;
7
7
  private abortController;
8
8
  private status;
9
+ private connectionGen;
9
10
  private listenersMap;
10
11
  private subscribedSet;
11
12
  private subscribeBatch;
@@ -54,6 +54,7 @@ class EventsClient {
54
54
  response;
55
55
  abortController;
56
56
  status = Status.Disconnected;
57
+ connectionGen = 0;
57
58
  listenersMap = new Map();
58
59
  subscribedSet = new Set();
59
60
  subscribeBatch;
@@ -103,12 +104,19 @@ class EventsClient {
103
104
  if (this.status !== Status.Disconnected)
104
105
  return;
105
106
  this.status = Status.Connecting;
106
- return (0, p_retry_1.default)(() => this.performConnect(), {
107
+ const gen = ++this.connectionGen;
108
+ return (0, p_retry_1.default)(() => this.performConnect(gen), {
107
109
  retries: connectRetries,
108
- onFailedAttempt: () => { this.status = Status.Disconnected; },
110
+ onFailedAttempt: () => {
111
+ if (this.connectionGen !== gen)
112
+ throw new p_retry_1.AbortError(new Error('cancelled'));
113
+ this.status = Status.Disconnected;
114
+ },
109
115
  });
110
116
  }
111
- async performConnect() {
117
+ async performConnect(gen) {
118
+ if (this.connectionGen !== gen)
119
+ return;
112
120
  if (this.status === Status.Connected)
113
121
  return;
114
122
  const [pResponse, abortController] = this.fetcher({ action: 'events-connect' });
@@ -178,6 +186,7 @@ class EventsClient {
178
186
  }
179
187
  }
180
188
  disconnect() {
189
+ this.connectionGen++;
181
190
  this.status = Status.Disconnected;
182
191
  this.abortController?.abort();
183
192
  this.listenersMap.forEach((_, name) => this.unsubscribeBatch.add(name));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "http-air",
3
- "version": "1.3.4",
3
+ "version": "1.3.5",
4
4
  "description": "HTTP library for batched RPC calls and real-time server-push over a single endpoint.",
5
5
  "main": "index.js",
6
6
  "repository": "https://github.com/yosbelms/http-air",