async function someAsyncFunc() {
const [user, categories] = await Promise.all([
asyncGetUser(),
asyncGetCategories()
]);
const mapping = await asyncMapUserWithCategory(user, categories);
};
To get the mapping
, I need to get user
and categories
first. These come from a DB, so I use Promise.all
to fetch them at once and then feed them to asyncMapUserWithCategory()
(not sure why I had put await before that, but nevermind). I am pretty sure asyncGetUser()
and asyncGetCategories()
must return promises. EDIT: .., or a value. (sorry, forgot about this)
In case I did the same without Promise.all
(below, I suppose slower) would the await-ed function also need to return promises for this to work?
async function someAsyncFunc() {
const user = await asyncGetUser();
const categories = await asyncGetCategories();
const mapping = await asyncMapUserWithCategory(user, categories);
};