Ecma262: Why聽don鈥檛 `Promise.{allSettled,all,race}` also聽support async聽iterators?

Created on 21 Mar 2020  路  2Comments  路  Source: tc39/ecma262

This聽is something that聽I鈥檇聽expect to聽be聽supported, since聽Promise.{allSettled,all,race} return聽a聽Promise, so聽they鈥檙e聽essentially already聽asynchronous.

question

Most helpful comment

It makes sense for all, but not so much allSettled or race (or any) - the expectation is that the promises returned by the async iterator settle in the order they're emitted (that's how async generators work, certainly), and that if one of them rejects then any subsequent promises just hold { done: true }.

It does not always make sense for promise-returning APIs which take iterables to also take async iterables.

Anyway, the iterator helpers proposal adds %AsyncIterator.prototype%.toArray(), which allows you to get a promise for a list out of an async iterator, which is a similar to what Promise.all does.

All 2 comments

It makes sense for all, but not so much allSettled or race (or any) - the expectation is that the promises returned by the async iterator settle in the order they're emitted (that's how async generators work, certainly), and that if one of them rejects then any subsequent promises just hold { done: true }.

It does not always make sense for promise-returning APIs which take iterables to also take async iterables.

Anyway, the iterator helpers proposal adds %AsyncIterator.prototype%.toArray(), which allows you to get a promise for a list out of an async iterator, which is a similar to what Promise.all does.

Closing this as resolved, but @ExE-Boss if there's something else feel free to reopen.

Was this page helpful?
0 / 5 - 0 ratings