sen-ether-client 0.2.3 → 0.2.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/lib/sen.js +16 -4
- package/package.json +1 -1
package/lib/sen.js
CHANGED
|
@@ -657,7 +657,8 @@ export class Sen extends EventEmitter {
|
|
|
657
657
|
await session.connect({
|
|
658
658
|
...baseConfig,
|
|
659
659
|
session: sessionName,
|
|
660
|
-
target
|
|
660
|
+
target,
|
|
661
|
+
rediscoverTargetOnReconnect: true
|
|
661
662
|
});
|
|
662
663
|
} catch (error) {
|
|
663
664
|
this.sessions.delete(sessionName);
|
|
@@ -921,6 +922,9 @@ export class Sen extends EventEmitter {
|
|
|
921
922
|
}
|
|
922
923
|
|
|
923
924
|
async #reconnectTarget(options) {
|
|
925
|
+
if (options.rediscoverTargetOnReconnect) {
|
|
926
|
+
return await this.#discoverTarget({ ...options, target: undefined });
|
|
927
|
+
}
|
|
924
928
|
if (options.tcpHub || !options.target) {
|
|
925
929
|
return await this.#discoverTarget(options);
|
|
926
930
|
}
|
|
@@ -1237,6 +1241,7 @@ export class SenBus extends EventEmitter {
|
|
|
1237
1241
|
this.interests = new Map();
|
|
1238
1242
|
this.pendingCalls = new Map();
|
|
1239
1243
|
this.nextTicketId = 1;
|
|
1244
|
+
this.reconnectPrepared = false;
|
|
1240
1245
|
}
|
|
1241
1246
|
|
|
1242
1247
|
startInterest(query, options = {}) {
|
|
@@ -1279,14 +1284,20 @@ export class SenBus extends EventEmitter {
|
|
|
1279
1284
|
}
|
|
1280
1285
|
|
|
1281
1286
|
prepareReconnect() {
|
|
1287
|
+
if (this.reconnectPrepared) {
|
|
1288
|
+
return;
|
|
1289
|
+
}
|
|
1290
|
+
this.reconnectPrepared = true;
|
|
1291
|
+
const detail = { reason: 'reconnect' };
|
|
1282
1292
|
for (const call of this.pendingCalls.values()) {
|
|
1283
1293
|
clearTimeout(call.timeout);
|
|
1284
1294
|
call.reject(new Error('SEN connection closed before method response'));
|
|
1285
1295
|
}
|
|
1286
1296
|
this.pendingCalls.clear();
|
|
1287
|
-
for (const object of this.objectsById.values()) {
|
|
1297
|
+
for (const object of [...this.objectsById.values()]) {
|
|
1288
1298
|
object.stale = true;
|
|
1289
|
-
object.emit('stale');
|
|
1299
|
+
object.emit('stale', detail);
|
|
1300
|
+
this.#removeObjectFromAllInterests(object, detail);
|
|
1290
1301
|
}
|
|
1291
1302
|
this.objectsById.clear();
|
|
1292
1303
|
this.typeRegistry.clear();
|
|
@@ -1297,7 +1308,7 @@ export class SenBus extends EventEmitter {
|
|
|
1297
1308
|
for (const interest of this.interests.values()) {
|
|
1298
1309
|
interest.closeLocal();
|
|
1299
1310
|
interest.objectsById.clear();
|
|
1300
|
-
interest.emit('stale');
|
|
1311
|
+
interest.emit('stale', detail);
|
|
1301
1312
|
}
|
|
1302
1313
|
}
|
|
1303
1314
|
|
|
@@ -1308,6 +1319,7 @@ export class SenBus extends EventEmitter {
|
|
|
1308
1319
|
});
|
|
1309
1320
|
const joined = await this.sen.client.joinBus(this.name);
|
|
1310
1321
|
this.id = joined.busId;
|
|
1322
|
+
this.reconnectPrepared = false;
|
|
1311
1323
|
const participantReadyTimeoutMs = Math.min(timeoutMs, this.sen.options.participantReadyTimeoutMs ?? 1000);
|
|
1312
1324
|
await waitForEvent(this.sen.client, 'busParticipantReady', participantReadyTimeoutMs).catch(error => {
|
|
1313
1325
|
this.sen.emit('warning', error);
|