等待执行蓝鸟中的所有承诺

Wait for execution of all promises in bluebird

我想等待所有承诺解决或拒绝,并在 .then 中获得已解决承诺的结果,并在 ``

中获得错误
'use strict';

const Promise = require('bluebird')

var delayOne = Promise.method((p = 1) => p);

var delayTwo = (p = 1) => {
    throw new Error('asf');
};

Promise.all([delayOne(100), Promise.method(delayTwo)(10), delayOne(300)])
    .then((res) => console.log(res)) // no logs from here
    .catch((e) => console.log(e))
    .done();

但我只从 .catch 获取日志。我的错误在哪里?

Promise.all 等待所有承诺 fulfill,你想要获得被拒绝的承诺,你可以在你想要的承诺上添加 .reflect允许失败:

Promise.all([
  delayOne(100), 
  Promise.method(delayTwo)(10).reflect(), // reflect here
  delayOne(300)])
  .then((res) => console.log(res)) // no logs from here
  // don't `.catch(e => console.log(e))` it is not needed
  // done is deprecated, you don't need it