mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2025-12-09 00:28:51 +00:00
Reuse connectionPromise for relay connect.
This commit is contained in:
18
pool.ts
18
pool.ts
@@ -26,22 +26,16 @@ export class SimplePool {
|
||||
|
||||
async ensureRelay(url: string): Promise<Relay> {
|
||||
const nm = normalizeURL(url)
|
||||
const existing = this._conn[nm]
|
||||
if (existing && existing.status === 1) return existing
|
||||
|
||||
if (existing) {
|
||||
await existing.connect()
|
||||
return existing
|
||||
if (!this._conn[nm]) {
|
||||
this._conn[nm] = relayInit(nm, {
|
||||
getTimeout: this.getTimeout * 0.9,
|
||||
listTimeout: this.getTimeout * 0.9
|
||||
})
|
||||
}
|
||||
|
||||
const relay = relayInit(nm, {
|
||||
getTimeout: this.getTimeout * 0.9,
|
||||
listTimeout: this.getTimeout * 0.9
|
||||
})
|
||||
this._conn[nm] = relay
|
||||
|
||||
const relay = this._conn[nm]
|
||||
await relay.connect()
|
||||
|
||||
return relay
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user