Promise.all and Async Task unit throw involved ....

Source: Internet
Author: User
Tags try catch
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

Keep in mind that promise.all just async tasks to do the final synchronization, will not bring the environment into the promise.all, so note that in each async, throw "execution environment" has a try Catch

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.