📜  javascript 减少承诺 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:58.834000             🧑  作者: Mango

代码示例1
const sum = await [
  Promise.resolve(1),
  Promise.resolve(1),
  Promise.resolve(1)
].reduce(async (previousPromise, itemPromise) => {
  const sum = await previousPromise;
  const item = await itemPromise;
  return sum + item;
}, Promise.resolve(0))

// sum === 3