From 0b87aa26073121150468b254304a051265577a06 Mon Sep 17 00:00:00 2001 From: Tom Schindl Date: Fri, 10 Nov 2023 12:54:06 +0100 Subject: [PATCH] wait for all promises to resolve/reject Instead of fail fast all remotes are awaited and only then the code proceeds to the next stage --- .../src/lib/loader/dynamic-federation.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/libs/mf-runtime/src/lib/loader/dynamic-federation.ts b/libs/mf-runtime/src/lib/loader/dynamic-federation.ts index 759ba788..c08a16bf 100644 --- a/libs/mf-runtime/src/lib/loader/dynamic-federation.ts +++ b/libs/mf-runtime/src/lib/loader/dynamic-federation.ts @@ -322,5 +322,18 @@ async function loadRemoteEntries() { } } - await Promise.all(promises); + const allSettledPromises = promises.map( p => { + return Promise.resolve(p).then( + value => ( { status: 'fulfilled', value } as const ), + reason => ( { status: 'rejected', reason } as const ) + ) + }); + + const result = await Promise.all(allSettledPromises); + const rejected = result.filter(isRejected).map( s => s.reason ); + return rejected.length > 0 ? Promise.reject(rejected) : Promise.resolve(); +} + +function isRejected(status: Record): status is { status: 'rejected', reason: any } { + return 'status' in status && status.status === 'rejected'; }