A page might need user details, recent posts, and tags from three endpoints before rendering. Starting those requests without waiting for one another avoids unnecessary sequential delays, but the caller still needs a way to know when all the data is ready.
Promise.all() combines multiple values or promises into one promise, preserving input order in its fulfilled results.
Implement your own version of Promise.all, called promiseAll, except that the function takes an array instead of a generic iterable.
[].// Resolved example.const p0 = Promise.resolve(3);const p1 = 42;const p2 = new Promise((resolve, reject) => {setTimeout(() => {resolve('foo');}, 100);});await promiseAll([p0, p1, p2]); // [3, 42, 'foo']
// Rejection example.const p0 = Promise.resolve(30);const p1 = new Promise((resolve, reject) => {setTimeout(() => {reject('An error occurred!');}, 100);});try {await promiseAll([p0, p1]);} catch (err) {console.log(err); // 'An error occurred!'}