mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2025-12-08 16:28:49 +00:00
more automatic cleanup of event listeners.
This commit is contained in:
13
relay.ts
13
relay.ts
@@ -135,15 +135,22 @@ export function relayInit(url: string): Relay {
|
||||
return
|
||||
case 'EOSE': {
|
||||
let id = data[1]
|
||||
;(subListeners[id]?.eose || []).forEach(cb => cb())
|
||||
if (id in subListeners) {
|
||||
subListeners[id].eose.forEach(cb => cb())
|
||||
subListeners[id].eose = [] // 'eose' only happens once per sub, so stop listeners here
|
||||
}
|
||||
return
|
||||
}
|
||||
case 'OK': {
|
||||
let id: string = data[1]
|
||||
let ok: boolean = data[2]
|
||||
let reason: string = data[3] || ''
|
||||
if (ok) pubListeners[id]?.ok.forEach(cb => cb())
|
||||
else pubListeners[id]?.failed.forEach(cb => cb(reason))
|
||||
if (id in pubListeners) {
|
||||
if (ok) pubListeners[id].ok.forEach(cb => cb())
|
||||
else pubListeners[id].failed.forEach(cb => cb(reason))
|
||||
pubListeners[id].ok = [] // 'ok' only happens once per pub, so stop listeners here
|
||||
pubListeners[id].failed = []
|
||||
}
|
||||
return
|
||||
}
|
||||
case 'NOTICE':
|
||||
|
||||
Reference in New Issue
Block a user