Javascript 。然后在'执行;待定';而不是承诺

Javascript 。然后在'执行;待定';而不是承诺,javascript,arrays,es6-promise,Javascript,Arrays,Es6 Promise,为什么下面的代码会记录一系列挂起的承诺?我希望数组中的所有承诺都得到解析,然后在.then方法中执行函数 for (let i = 0; i < limit; i++) { promiseArray.push(fetch(someUrls[i])) } Promise.all(promiseArray) .then(responses => responses.map(response => response.text())) .then(result

为什么下面的代码会记录一系列挂起的承诺?我希望数组中的所有承诺都得到解析,然后在.then方法中执行函数

for (let i = 0; i < limit; i++) {
    promiseArray.push(fetch(someUrls[i]))
}

Promise.all(promiseArray)
    .then(responses => responses.map(response => response.text()))
    .then(result => console.log(result))
for(设i=0;iresponses.map(response=>response.text())
.then(result=>console.log(result))
提前谢谢,那是因为
fetch
是一个双承诺的东西。一个用于实际请求,另一个用于转换

您可以做的是将
array.map
操作包装到另一个
Promise.all

Promise.all(promiseArray)
    .then(responses => Promise.all(responses.map(response => response.text())))
    .then(result => console.log(result))
那是因为
fetch
是一个双承诺的东西。一个用于实际请求,另一个用于转换

您可以做的是将
array.map
操作包装到另一个
Promise.all

Promise.all(promiseArray)
    .then(responses => Promise.all(responses.map(response => response.text())))
    .then(result => console.log(result))

您需要将chained-then放入
承诺中。所有
都作为
响应。text()
还返回另一个承诺

for (let i = 0; i < limit; i++) {
    promiseArray.push(fetch(someUrls[i]))
}

Promise.all(promiseArray)
    .then(responses => Promise.all(responses.map(response => response.text()))) //Needs to wait for all text() promise methods to resolve
    .then(result => console.log(result))
for(设i=0;iPromise.all(responses.map(response=>response.text()))//需要等待所有text()Promise方法解析
.then(result=>console.log(result))
或者,您可以在for循环中链接承诺:

for (let i = 0; i < limit; i++) {
    promiseArray.push(fetch(someUrls[i]).then(res => res.text()));
}

Promise.all(promiseArray).then(result => console.log(result))
for(设i=0;ires.text());
}
promiseArray.then(result=>console.log(result))

您需要将chained然后放入一个
承诺中。所有
也作为
响应。text()
还返回另一个承诺

for (let i = 0; i < limit; i++) {
    promiseArray.push(fetch(someUrls[i]))
}

Promise.all(promiseArray)
    .then(responses => Promise.all(responses.map(response => response.text()))) //Needs to wait for all text() promise methods to resolve
    .then(result => console.log(result))
for(设i=0;iPromise.all(responses.map(response=>response.text()))//需要等待所有text()Promise方法解析
.then(result=>console.log(result))
或者,您可以在for循环中链接承诺:

for (let i = 0; i < limit; i++) {
    promiseArray.push(fetch(someUrls[i]).then(res => res.text()));
}

Promise.all(promiseArray).then(result => console.log(result))
for(设i=0;ires.text());
}
promiseArray.then(result=>console.log(result))