我想等待所有承诺解决或拒绝,并在.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
获取日志。我的错误在哪里?
答案 0 :(得分:2)
Promise.all
等待履行的所有承诺,您希望得到拒绝的承诺,您可以在承诺失败的承诺上添加.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