[英]Javascript - forEach with promise.all not working
我試圖為每個人處理承諾但沒有工作
我認為它會因為console.log(result)
而記錄一些東西。
為什么它不起作用?
它只記錄
All done (54) [ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ]
let promises = [];
mkt.forEach(async function (marketItem, index) {
promises.push(() => {
context.program.account.chain
.fetch(sth)
.then((result) => {
console.log(result)
});
});
});
Promise.all(promises)
.then(results => {
console.log('All done', results);
})
.catch(e => {
// Handle errors here
});
你可以試試這個
let promises = mkt.map((marketItem, index) => {
return context.program.account.chain.fetch(sth)
});
Promise.all(promises).then(results => {
console.log('All done', results);
})
.catch(e => {
// Handle errors here
});
不要推解決的promise,推promise。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.