diff options
| author | Adam Soltys <[email protected]> | 2026-10-01 15:31:10 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-10-01 15:31:10 -0700 |
| commit | a7806172f7ede9be345750c93e5fa72e10e9b953 (patch) | |
| tree | 00e431cb056a39fc58f6b23376cd4446f08f6616 /src/nostr.js | |
| parent | 1da40523fc00b9963012abe067a6c4910c7578b6 (diff) | |
| download | coinosv3-a7806172f7ede9be345750c93e5fa72e10e9b953.tar.gz coinosv3-a7806172f7ede9be345750c93e5fa72e10e9b953.zip | |
Stream ready feed posts without waiting for catch-up batches
Diffstat (limited to 'src/nostr.js')
| -rw-r--r-- | src/nostr.js | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/nostr.js b/src/nostr.js index f4dfa59..a3cab53 100644 --- a/src/nostr.js +++ b/src/nostr.js @@ -246,6 +246,25 @@ export async function queryOn(relays, filter, maxWait = 1500) { return evs.filter((_, i) => oks[i]); } catch { return []; } } +// A bounded query that delivers verified events before the slowest relay's +// EOSE. Completion also waits for verification and the consumer's work. +export async function queryStreamOn(relays, filter, onEvent, maxWait = 1500) { + probeRelays(relays); + const pending = []; + try { + const live = liveRelays(relays); + if (!live.length) return; + await new Promise((resolve) => { + pool.subscribeManyEose(live, filter, { + maxWait, + onevent(event) { + pending.push(verifyOneAsync(event).then((ok) => ok && onEvent(event)).catch(() => {})); + }, + onclose: resolve, + }); + }); + } catch {} finally { await Promise.all(pending); } +} export async function publishOn(relays, evt) { try { const live = liveRelays(relays); |
