move `wakuDisconnectionTimer` to constructor

This commit is contained in:
Felicio Mununga 2022-11-27 22:52:24 +01:00
parent e20df9b0bb
commit 634ec4eeca
No known key found for this signature in database
GPG Key ID: 0EB8D75C775AB6F1
1 changed files with 15 additions and 20 deletions

View File

@ -61,15 +61,23 @@ class Client {
storage: Storage
constructor(
waku: WakuLight,
wakuDisconnectionTimer: ReturnType<typeof setInterval>,
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<void>[] = []
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<void>[] = []
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()