ken*_*tor 0 javascript node.js promise bluebird
我有两个promises,每个都返回一个字符串数组.我运行它们Promise.all(p1, p2)但我很惊讶它解析的值参数是一个12k字符串的数组(这将是两个promises'返回之一).
const p1 = ModelA.find()
.then((bandProfiles) => {
const bandProfilePlayerTags = []
// [...] Filling this array with strings
return bandProfilePlayerTags
})
const p2 = ModelB.find()
.then((response) => {
const playerTags = []
// [...] Filling this array with strings
return playerTags
})
Promise.all(p1, p2).then((values) => {
// Values is an array containing more than 12k strings
})
Run Code Online (Sandbox Code Playgroud)
我期望值是一个长度为2的数组.values[0]将是来自promise 1 values[1]的返回数组,并且是来自promise 2的返回数组.我在这里缺少什么?
尝试在类似的数组中传递p1和p2
const p1 = ModelA.find()
.then((bandProfiles) => {
const bandProfilePlayerTags = []
// [...] Filling this array with strings
return bandProfilePlayerTags
})
const p2 = ModelB.find()
.then((response) => {
const playerTags = []
// [...] Filling this array with strings
return playerTags
})
Promise.all([p1, p2]).then((values) => {
// Values is an array containing more than 12k strings
})
Run Code Online (Sandbox Code Playgroud)
Promise.all(迭代); 期望可迭代对象作为参数
| 归档时间: |
|
| 查看次数: |
569 次 |
| 最近记录: |