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.
- package/lib/client/events.d.ts +1 -0
- package/lib/client/events.js +12 -3
- package/package.json +1 -1
package/lib/client/events.d.ts
CHANGED
package/lib/client/events.js
CHANGED
|
@@ -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
|
-
|
|
107
|
+
const gen = ++this.connectionGen;
|
|
108
|
+
return (0, p_retry_1.default)(() => this.performConnect(gen), {
|
|
107
109
|
retries: connectRetries,
|
|
108
|
-
onFailedAttempt: () => {
|
|
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