【发布时间】:2016-03-28 07:06:41
【问题描述】:
为什么我的 Promise 一直处于待处理状态,我该如何解决?
var foundPeopleA = findPeopleA().then(function(result) {
var res = []
result.map(function(el) {
res.push(getProfileXML(el.sid));
});
return res
});
var foundPeopleB = findPeopleB().then(function(result) {
var res = []
result.map(function(el) {
res.push(getProfileXML(el.sid));
});
return res
})
return Promise.all([findPeopleA, findPeopleB]).then(function(results) {
console.log(results) //[ [ Promise { <pending> }, Promise { <pending> } ], [ Promise { <pending> }, Promise { <pending> } ] ]
})
但是,如果我将上述 2 个函数的主体更改为
var res
result.map(function(el) {
res = getProfileXML(el.sid);
});
return res
他们不会挂起,我会得到结果。
【问题讨论】:
标签: javascript promise es6-promise