handle connection failure on pool according to @chmac.

fixes https://github.com/nbd-wtf/nostr-tools/issues/130
This commit is contained in:
fiatjaf
2023-02-24 09:34:19 -03:00
parent f43d23d344
commit 344762820c

15
pool.ts
View File

@@ -54,7 +54,13 @@ export class SimplePool {
}, 2400)
relays.forEach(async relay => {
let r = await this.ensureRelay(relay)
let r
try {
r = await this.ensureRelay(relay)
} catch (err) {
handleEose()
return
}
if (!r) return
let s = r.sub(filters, modifiedOpts)
s.on('event', (event: Event) => {
@@ -63,14 +69,17 @@ export class SimplePool {
})
s.on('eose', () => {
if (eoseSent) return
handleEose()
})
subs.push(s)
function handleEose() {
eosesMissing--
if (eosesMissing === 0) {
clearTimeout(eoseTimeout)
for (let cb of eoseListeners.values()) cb()
}
})
subs.push(s)
}
})
let greaterSub: Sub = {