在每个内部执行并行的Promise

我正在尝试在forEach中执行一组诺言A,B,C,D。这些承诺应按顺序对所有列表项并行执行。我希望执行能够等到所有承诺都解决为止。但是,一旦遇到forEach内部的第一个承诺,流程就开始并行处理其他功能。 在下面的代码段中,解决列表中的所有promise后,应触发thirdCall。但是,它仍然不起作用

async function getList(value) {
  return someList;
}

async function processList(list) {
  try {
    await list.forEach(async (element) => {
      await A(element.firstProperty); // console jumps to thirdCall() while executing A,B,C,D in parallel
      await B(element.secondProperty);
      await C(element.thirdProperty);
      await D(element.fourthProperty);
    });
    return response;
  } catch (e) {
    throw (e);
  }
}

async function thirdCall() {
  try {
    let someresult = someProcessing(); // this should start execution ONLY AFTER processList() is done.
    await E(someresult);
    thirdCallResponse;
  } catch (error) {
    console.log(`error deleting policy ${error}`);
    throw error;
  }
}

async function processValue(value) {
  try {
    const list = await getList(value);
    await processList(list);
    await thirdCall(value);
  } catch (error) {
    console.log(error);
  }
}

processValue('someGuid');


zyyzyyzhaoyiying 回答:在每个内部执行并行的Promise

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3153677.html

大家都在问