我有多个这样的 promise :
module.exports = function (a, b, c) {
return someAsync(() => {
someFunc(a);
})
.then(() => myPromises(a, b, c))
.then(result => {
console.log('log the result: ', JSON.stringify(result)); // empty
})
};
const myPromises = function myPromises(a, b, c){
Promise.all([
somePromise(a),
someOtherPromise(b)
]).then(function (data) {
Promise.all([
anotherPromise(data[0]),
yetanotherPromise(data[1])
]).then(function (finalResult) {
console.log('check out finalResult: ', JSON.stringify(finalResult)); // i see the expected results here
return finalResult;
}).catch(err => { return err });
}).catch(err => { return err });
};
为什么 console.log('log the result: ', JSON.stringify(result));
返回空?换句话说,为什么这一行在promise.all完成之前就被执行了?
我怎样才能让它等待所有 promise 然后执行?
最佳答案
不确定您想要返回哪个 Promise,但总体思路是返回 Promise.all,而不是仅仅调用 Promise.all。
const myPromises = function myPromises(a, b, c){
return Promise.all([
关于javascript nodejs promise 所有内容稍后执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49420361/