js promise.all callback code example
Example 1: javascript promise.all
try {
const [res1, res2, res3] = await Promise.all([
Promise1,
Promise2,
Promise3,
]);
} catch (err) {
console.error(err);
}
Example 2: javascript promise.all
async function fetchMoviesAndCategories() {
const [moviesResponse, categoriesResponse] = await Promise.all([
fetch('/movies'),
fetch('/categories')
]);
const movies = await moviesResponse.json();
const categories = await categoriesResponse.json();
return [movies, categories];
}