If we want to run multiple unrelated promises at once, then we should use Promise.all
.
For instance, we can run them all at once as follows:
Promise.all([
promise1,
promise2,
promise3,
])
.then((res) => {
//...
})
If we use async
and await
, we can write:
(async () => {
const [val1, val2, val3] = await Promise.all([
promise1,
promise2,
promise3,
])
})();
In both examples, the resolved values of all three promises are either in res
or assigned to an array on the left (in the second example).
This way, they run all at once instead of waiting for each to resolve.