From 0b93db7fad686ba9bdb69bd081c7d948b997aa8b Mon Sep 17 00:00:00 2001 From: Junho Yeo Date: Wed, 12 Oct 2022 04:46:26 +0900 Subject: [PATCH] [web] Use `reduce` in `safePromiseAll` to make it work for 2D arrays (#309) --- packages/bento-common/utils/safer-promises.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/bento-common/utils/safer-promises.ts b/packages/bento-common/utils/safer-promises.ts index 25630afe..f11e49f4 100644 --- a/packages/bento-common/utils/safer-promises.ts +++ b/packages/bento-common/utils/safer-promises.ts @@ -1,6 +1,7 @@ export const safePromiseAll = async (promises: Promise[]) => - (await Promise.allSettled(promises)).flatMap((res) => - res.status === 'fulfilled' ? res.value : [], + (await Promise.allSettled(promises)).reduce( + (acc, res) => (res.status === 'fulfilled' ? [...acc, res.value] : acc), + [] as T[], ); export const safeAsyncFlatMap = async (