本文介绍了等待承诺在阵列中解决的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
具有
按照@Bergi的评论,我必须相应地更正我的答案,才能脱离反模式领域。
OK as per @Bergi's comment i have to correct my answer accordingly in order to take it off of anti-pattern realm.
function handleRejectedPromises(p){
return p.then(v => ({status: "resolved", value: v}))
.catch(x => ({status: "rejected", reason: x}));
}
var ps = [Promise.resolve(42), Promise.reject(37), Promise.resolve(23), Promise.resolve(11)];
Promise.all(ps.map(p => handleRejectedPromises(p)))
.then(ra => ra.forEach(r => console.log(r)));
这篇关于等待承诺在阵列中解决的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!