From 11499ec04f07265a5b1e7c5c87525cd9da488c22 Mon Sep 17 00:00:00 2001 From: Jonathan Staab Date: Wed, 20 Sep 2023 17:49:23 -0700 Subject: [PATCH] Return unsubscribe from load --- package.json | 2 +- src/Executor.ts | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 6cc7753..e15158c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "paravel", - "version": "0.3.5", + "version": "0.3.6", "description": "Yet another toolkit for nostr", "author": "hodlbod", "license": "MIT", diff --git a/src/Executor.ts b/src/Executor.ts index 9eeeef1..9721844 100644 --- a/src/Executor.ts +++ b/src/Executor.ts @@ -100,13 +100,13 @@ export class Executor { load(filters: Filter[], {timeout = 30_000, onEvent, onEose, onClose}: LoadOpts) { const eose = new Set() - const close = () => { + const unsubscribe = () => { onClose?.() sub.unsubscribe() clearTimeout(handle) } - const handle = setTimeout(close, timeout) + const handle = setTimeout(unsubscribe, timeout) const sub = this.subscribe(filters, { onEvent, @@ -115,10 +115,12 @@ export class Executor { eose.add(url) if (eose.size === this.target.connections.length) { - close() + unsubscribe() } }, }) + + return {unsubscribe} } }