Return unsubscribe from load

This commit is contained in:
Jonathan Staab
2023-09-20 17:49:23 -07:00
parent 7be9591557
commit 11499ec04f
2 changed files with 6 additions and 4 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "paravel", "name": "paravel",
"version": "0.3.5", "version": "0.3.6",
"description": "Yet another toolkit for nostr", "description": "Yet another toolkit for nostr",
"author": "hodlbod", "author": "hodlbod",
"license": "MIT", "license": "MIT",
+5 -3
View File
@@ -100,13 +100,13 @@ export class Executor {
load(filters: Filter[], {timeout = 30_000, onEvent, onEose, onClose}: LoadOpts) { load(filters: Filter[], {timeout = 30_000, onEvent, onEose, onClose}: LoadOpts) {
const eose = new Set() const eose = new Set()
const close = () => { const unsubscribe = () => {
onClose?.() onClose?.()
sub.unsubscribe() sub.unsubscribe()
clearTimeout(handle) clearTimeout(handle)
} }
const handle = setTimeout(close, timeout) const handle = setTimeout(unsubscribe, timeout)
const sub = this.subscribe(filters, { const sub = this.subscribe(filters, {
onEvent, onEvent,
@@ -115,10 +115,12 @@ export class Executor {
eose.add(url) eose.add(url)
if (eose.size === this.target.connections.length) { if (eose.size === this.target.connections.length) {
close() unsubscribe()
} }
}, },
}) })
return {unsubscribe}
} }
} }