From 56a0dbb4325656d4bdeec3e1829123a27412416a Mon Sep 17 00:00:00 2001 From: silberengel Date: Sun, 3 Aug 2025 09:59:24 +0200 Subject: [PATCH] return first result --- src/lib/utils/websocket_utils.ts | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/lib/utils/websocket_utils.ts b/src/lib/utils/websocket_utils.ts index 5c12c98..659580e 100644 --- a/src/lib/utils/websocket_utils.ts +++ b/src/lib/utils/websocket_utils.ts @@ -152,7 +152,7 @@ export async function fetchNostrEvent(filter: NostrFilter): Promise((resolve) => { setTimeout(() => { console.warn("[WebSocket Utils]: Fetch timeout reached"); @@ -160,18 +160,12 @@ export async function fetchNostrEvent(filter: NostrFilter): Promise { - // Find the first successful result - for (const result of results) { - if (result.status === 'fulfilled' && result.value) { - return result.value; - } - } - return null; - }); - - // Race between the fetch and the timeout - const result = await Promise.race([fetchPromise, timeoutPromise]); + // Race between individual relay results and the timeout + const result = await Promise.race([ + // Wait for the first successful result from any relay + Promise.race(relayPromises.filter(p => p !== null)), + timeoutPromise + ]); if (result) { return result;