promise.all 与 async task unit中throw的牵扯。。。。。。。

来源:互联网 发布:杭州淘宝模特培训学校 编辑:程序博客网 时间:2024/05/20 09:48
async function test1() {  // throw new Error('eeeee')console.log('test');return 1;}async function test2() {  // throw new Error('error2');  return 2;}const asyncTasks = [1, 2, 3].map(async (x) => {  if(x === 2){    // throw new Error('error: 44');  }})console.log(asyncTasks);(async () => {  try{    const a = await Promise.all([1, 2, 3].map(async (x) => {      if(x === 2){         throw new Error('error: 44');      }    }));    const a = await Promise.all(asyncTasks);    console.log(a[0]);  }catch(e) {    console.log('e = ', e);  }})()dan

谨记promise.all只是把async tasks做最后的同步,不会把环境带入promise.all中,所以注意在每个async中throw的”执行环境“是否有try catch

原创粉丝点击