Skip to content

Commit

Permalink
[web] Use reduce in safePromiseAll to make it work for 2D arrays (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
junhoyeo authored Oct 11, 2022
1 parent 715509b commit 0b93db7
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/bento-common/utils/safer-promises.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export const safePromiseAll = async <T extends any>(promises: Promise<T>[]) =>
(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 <T extends any, U extends any>(
Expand Down

0 comments on commit 0b93db7

Please sign in to comment.