From fbdae298df3207bbedb46ede80945d5244ce6d5b Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Mon, 11 Nov 2024 15:47:31 -0500 Subject: [PATCH] fixed serialResolve --- packages/sessions/src/trackers/multiple.ts | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/packages/sessions/src/trackers/multiple.ts b/packages/sessions/src/trackers/multiple.ts index 9fd7f199d..a66e2f274 100644 --- a/packages/sessions/src/trackers/multiple.ts +++ b/packages/sessions/src/trackers/multiple.ts @@ -32,15 +32,19 @@ export function raceUntil(promises: Promise[], fallback: T, evalRes: (val: }) } -export function serialResolve(promises: Promise[], fallback: T, evalRes: (val: T) => boolean): Promise { - return new Promise(resolve => { - for (const p of promises) { - p.then(val => { - if (evalRes(val)) resolve(val) - }) +export async function serialResolve(promises: Promise[], fallback: T, evalRes: (val: T) => boolean): Promise { + for (const p of promises) { + try { + const val = await p + if (evalRes(val)) { + return val + } + } catch { + // Continue to next promise if this one fails + continue } - resolve(fallback) - }) + } + return fallback } export async function allSafe(promises: Promise[], fallback: T): Promise {