# Extend \`Promise.all\` support \`async iterator\`.

**URL:** <https://es.discourse.group/t/extend-promise-all-support-async-iterator/491>\
**Category:** I have questions\
**Created:** [October 3, 2020, 2:44pm UTC](https://es.discourse.group/t/extend-promise-all-support-async-iterator/491 "2020-10-03T14:44:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![septs](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/septs/32/395_2.png) [@septs](https://es.discourse.group/u/septs)\
**Post date:** [October 3, 2020, 2:44pm UTC](https://es.discourse.group/t/extend-promise-all-support-async-iterator/491/1 "2020-10-03T14:44:42Z")

</div>

`Iterator` can using `Array.from` expansion,

But `AsyncIterator` no way to expansion to array.

Make `Promise.all` support `AsyncIterator` input.

Can avoid implementing it yourself

```javascript
async function * foo() {
    yield 1
    yield 2
    yield 3
    yield 4
}

const result = await Promise.all(foo());
// Output: [1, 2, 3, 4]

```

---

<div class="post-metadata">

**Author:** ![bergus](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/bergus/32/152_2.png) [@bergus](https://es.discourse.group/u/bergus)\
**Post date:** [October 3, 2020, 4:14pm UTC](https://es.discourse.group/t/extend-promise-all-support-async-iterator/491/2 "2020-10-03T16:14:47Z")

</div>

I think `Promise.all` should stay reserved for the use case of watching a known set of promises to become fulfilled, it should not be extended to support dynamically growing sets. I'd assume this would also break compatibility for objects that are both synchronously and asynchronously iterable.

As a better solution, the [_iterator helpers_ proposal](https://github.com/tc39/proposal-iterator-helpers) already contains a `AsyncIterator.prototype.toArray` method which can be used as

```javascript
const result = await foo().toArray();

```
