const arr = {}; await Promise.all( UsersQuery.map(async function (data) { const city = await db.sequelize.query(` select * from city `, type: db.sequelize.QueryTypes.SELECT }); arr[data.user_id] = city[0].name; }) } UsersQuery.forEach(async function (data, index) { this[index].name = arr[data.user_id]; }, UsersQuery);
https://stackoverflow.com/questions/30362733/handling-errors-in-promise-all
Promise.all(state.routes.map(function(route) { return route.handler.promiseHandler().catch(function(err) { return err; }); })) .then(function(arrayOfValuesOrErrors) { // handling of my array containing values and/or errors. }) .catch(function(err) { console.log(err.message); // some coding error in handling happened }); Alternately, if you have a case where you don’t particularly care about the values of the resolved promises when there is one failure but you still want them to have run, you could do something like this which will resolve with the promises as normal when they all succeed and reject with the failed promises when any of them fail:
async getaaa()
async getbbb()
async getccc()
=======new way=======
async refreshall(){
await Promise.all( xxxxxx.map(async (value, index) =>{
aaa = await getaaa()
}))
await Promise.all( xxxxxx.map(async (value, index) =>{
bbb = await getbbb()
}))
await Promise.all( xxxxxx.map(async (value, index) =>{
ccc = await getccc()
}))
}
=======old way=======
async refreshall(){
await Promise.all( xxxxxx.map(async (value, index) =>{
aaa = await getaaa()
bbb = await getbbb()
ccc = await getccc()
https://hackmd.io/s/Bko9gUGYZ