JavaScript Reference ยท Promises and Async
Promise.all()
Reference for Promise.all(): run promises in parallel, get results in input order, fail fast on the first rejection, and handle empty or non-promise input.
Promise.all() takes an iterable of promises (or plain values) and returns one promise. That promise fulfills with an array of all the results, in the same order as the input, once every input has fulfilled. If any input rejects, it rejects immediately with that reason.
Use it when the tasks are independent and you need all of them before you can continue, for example loading several resources at once instead of one after the other.
const [user, posts] = await Promise.all([loadUser(), loadPosts()]);
Try it
Press Run (or Ctrl + Enter) to see the console output here.
No output.
Press Run (or Ctrl + Enter) to see the console output here.
No output.
Syntax
Promise.all(iterable)
| Name | Description |
|---|---|
iterable |
An iterable such as an array. Each element is passed through Promise.resolve(), so plain values and thenables are accepted. |
Return value: a promise. It fulfills with an array of the fulfillment values, in input order. For an empty iterable it fulfills with []. It rejects with the reason of the first input that rejects.
Exceptions: if iterable is not iterable, the returned promise rejects with a TypeError.
Usage notes
- Order follows the input, not the completion time.
- Fail fast. The first rejection settles the result at once. The other tasks are not cancelled and keep running; their results are simply ignored, and later rejections are silently handled.
- Everything starts immediately. Promises begin working when created, so
Promise.all()does not start anything; it only waits. - When you need every outcome, including failures, use
Promise.allSettled(). - Parallel mapping.
Promise.all(items.map(async (item) => ...))starts every task at once and gives results in item order. - Too much parallelism. Thousands of simultaneous requests may overload a server; process items in batches.
- Sequential alternative. When each step depends on the previous one, use a
for...ofloop withawait.
Browser support
Supported in every current browser and Node.js.