Created
April 21, 2026 02:41
-
-
Save librz/0713d1825a26c5ddb6dc0feaddb755a9 to your computer and use it in GitHub Desktop.
Resolve Promises In Parallel (Unified Promise.all & Promise.allSettled)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function isFulfilled<T>( | |
| result: PromiseSettledResult<T>, | |
| ): result is PromiseFulfilledResult<T> { | |
| return result.status === "fulfilled"; | |
| } | |
| export async function resolvePromisesInParallel<T>( | |
| promises: Promise<T>[], | |
| options?: { | |
| ignoreFailures?: boolean; | |
| }, | |
| ): Promise<T[]> { | |
| const { ignoreFailures = false } = options ?? {}; | |
| if (ignoreFailures) { | |
| const settledResult = await Promise.allSettled(promises); | |
| return settledResult.filter(isFulfilled).map((it) => it.value); | |
| } else { | |
| return Promise.all(promises); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment