Send close only if not already closed

This commit is contained in:
Jonathan Staab
2023-07-20 10:03:37 -07:00
parent 0b8eef041d
commit d6defe2844
2 changed files with 9 additions and 4 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "paravel",
"version": "0.1.16",
"version": "0.1.17",
"description": "Yet another toolkit for nostr",
"repository": {
"type": "git",
+8 -3
View File
@@ -8,6 +8,7 @@ export class Executor {
this.target = target
}
subscribe(filters, {onEvent, onEose}) {
const closed = false
const id = createSubId('REQ')
const eventListener = (url, subid, e) => subid === id && onEvent?.(url, e)
const eoseListener = (url, subid) => subid === id && onEose?.(url)
@@ -18,9 +19,13 @@ export class Executor {
return {
unsubscribe: () => {
this.target.send("CLOSE", id)
this.target.off('EVENT', eventListener)
this.target.off('EOSE', eoseListener)
if (!closed) {
this.target.send("CLOSE", id)
this.target.off('EVENT', eventListener)
this.target.off('EOSE', eoseListener)
}
closed = true
},
}
}