How to handle multiple Promises in JavaScript?
We can handle multiple Promises in several ways one of them is by using Promise.all() method. In this post I am going to demonstrate how we can handle multiple Promises using Promise.all() method.
Example:
async function fetchData() {
const [users, products] =
await Promise.all([
(await fetch('https://api.example.com/user/all'))
.json(),
(await fetch('https://api.example.com/product/all'))
.json(),
]);
console.log(users);
console.log(products);
}
fetchData();