move `wakuDisconnectionTimer` to constructor
This commit is contained in:
parent
e20df9b0bb
commit
634ec4eeca
|
@ -61,15 +61,23 @@ class Client {
|
||||||
|
|
||||||
storage: Storage
|
storage: Storage
|
||||||
|
|
||||||
constructor(
|
constructor(waku: WakuLight, options: ClientOptions) {
|
||||||
waku: WakuLight,
|
|
||||||
wakuDisconnectionTimer: ReturnType<typeof setInterval>,
|
|
||||||
options: ClientOptions
|
|
||||||
) {
|
|
||||||
// Waku
|
// Waku
|
||||||
this.waku = waku
|
this.waku = waku
|
||||||
this.wakuMessages = new Set()
|
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
|
// Storage
|
||||||
this.storage = options.storage ?? new LocalStorage()
|
this.storage = options.storage ?? new LocalStorage()
|
||||||
|
@ -126,22 +134,9 @@ class Client {
|
||||||
[Protocols.Store, Protocols.Filter, Protocols.LightPush],
|
[Protocols.Store, Protocols.Filter, Protocols.LightPush],
|
||||||
10 * 1000
|
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
|
||||||
client = new Client(waku, wakuDisconnectionTimer, options)
|
client = new Client(waku, options)
|
||||||
|
|
||||||
// Community
|
// Community
|
||||||
await client.community.start()
|
await client.community.start()
|
||||||
|
|
Loading…
Reference in New Issue