是的,它们绝对不同。
for await应该与异步迭代器一起使用,而不是与预先存在的promise数组一起使用。
为了清楚起见,
for await (const res of items.map(e => somethingAsync(e))) …
与…相同
const promises = items.map(e => somethingAsync(e));for await (const res of promises) …
要么
const promises = [somethingAsync(items[0]), somethingAsync(items[1]), …);for await (const res of promises) …
somethingAsync在等待任何事情之前,这些呼叫立即立即发生。然后,
await一个接一个地编辑它们,如果其中任何一个被拒绝,这绝对是一个问题:这将导致未处理的promise拒绝错误。
使用
Promise.all是处理promise数组的唯一可行选择:
for (const res of await Promise.all(promises)) …
请参阅[等待多个并发的await操作](http://codingdict.com/questions/77320和[aprom
Promise.all()与多次await之间有什么区别?](http://codingdict.com/questions/77321有关详细信息。



