Promise.all map

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);

2020-04-20 · 1 min · 38 words · Me

promise.all error catch

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: ...

2020-03-05 · 1 min · 136 words · Me

async await Promise.all

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() })) } 1. map usually return something, here just throw 2. if use foreach(), get error. Like foreach is not function, can’t async await. ...

2018-05-24 · 1 min · 111 words · Me

[轉]async 、 await es6 promise javqscript

https://hackmd.io/s/Bko9gUGYZ

2017-08-29 · 1 min · word · Me