*Store the listenConnections connection so don't create duplicates incase init/ready is called multiple times

This commit is contained in:
Derrick Hammer 2023-03-19 14:02:50 -04:00
parent 14a71cffd9
commit 290ca18c4b
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 23 additions and 16 deletions

View File

@ -15,6 +15,10 @@ export class SwarmClient extends Client {
private _connectBackoff: any;
private _ready?: Promise<void>;
private _connectionListener?: [
sendUpdate: DataFn,
response: Promise<ErrTuple>
];
private _topics: Set<Uint8Array> = new Set<Uint8Array>();
private _sockets: Map<number, Socket> = new Map<number, Socket>();
@ -87,7 +91,8 @@ export class SwarmClient extends Client {
}
private async _listen() {
const connect = this.connectModule(
if (!this._connectionListener) {
this._connectionListener = this.connectModule(
"listenConnections",
{ swarm: this.swarm },
async (socketId: any) => {
@ -105,8 +110,10 @@ export class SwarmClient extends Client {
this.emit("connection", socket);
}
);
}
await connect[1];
await this._connectionListener[1];
this._connectionListener = undefined;
this.start();
}