From 3d5c490185eacd52689b2a0326baf00795ce19a7 Mon Sep 17 00:00:00 2001 From: Felicio Mununga Date: Sun, 27 Nov 2022 22:52:24 +0100 Subject: [PATCH] move `wakuDisconnectionTimer` to constructor --- packages/status-js/src/client/client.ts | 35 +++++++++++-------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/packages/status-js/src/client/client.ts b/packages/status-js/src/client/client.ts index 0ec3283a..ee2d7324 100644 --- a/packages/status-js/src/client/client.ts +++ b/packages/status-js/src/client/client.ts @@ -61,15 +61,23 @@ class Client { storage: Storage - constructor( - waku: WakuLight, - wakuDisconnectionTimer: ReturnType, - options: ClientOptions - ) { + constructor(waku: WakuLight, options: ClientOptions) { // Waku this.waku = waku this.wakuMessages = new Set() - this.#wakuDisconnectionTimer = wakuDisconnectionTimer + this.#wakuDisconnectionTimer = setInterval(async () => { + const connectionsToClose: Promise[] = [] + + for (const connection of this.waku.libp2p.connectionManager.getConnections()) { + try { + await this.waku.libp2p.ping(connection.remoteAddr) + } catch { + connectionsToClose.push(connection.close()) + } + } + + await Promise.allSettled(connectionsToClose) + }, 10 * 1000) // Storage this.storage = options.storage ?? new LocalStorage() @@ -126,22 +134,9 @@ class Client { [Protocols.Store, Protocols.Filter, Protocols.LightPush], 10 * 1000 ) - const wakuDisconnectionTimer = setInterval(async () => { - const connectionsToClose: Promise[] = [] - - for (const connection of waku!.libp2p.connectionManager.getConnections()) { - try { - await waku!.libp2p.ping(connection.remoteAddr) - } catch { - connectionsToClose.push(connection.close()) - } - } - - await Promise.allSettled(connectionsToClose) - }, 10 * 1000) // Client - client = new Client(waku, wakuDisconnectionTimer, options) + client = new Client(waku, options) // Community await client.community.start()