Return unsubscribe from load
This commit is contained in:
+1
-1
@@ -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
@@ -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}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user