Intent to Prototype: Array.fromAsync

91 views
Skip to first unread message

Matthew Gaudet

unread,
Mar 29, 2023, 3:55:52 PM3/29/23
to dev-pl...@mozilla.org

Summary:

 `Array.fromAsync` is a TC39 proposal [1] at Stage 3 of the TC39 standardization process [2]. It is the async sibling to `Array.from`, adapted to handle async iterators and promise-returning functions.

It allows the construction of an array of results from an async iterator, returning a promise for this array. Thus,

```
array = []
for await (x of asyncIter) {
  array.push(await x);
}
```

can be simplified to `array = await Array.asyncFrom(asyncIter)`.

Bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1746209
Specification: https://tc39.es/proposal-array-from-async/
Platform Coverage: All
Preference: Currently available in the JS shell using the option `--enable-array-from-async` . Will be preffable under `javascript.options.experimental.enable_array_from_async` when Bug 1825356 lands.
Documentation: MDN documentation tracked here https://github.com/mdn/content/issues/22145

Other Browsers: Safari Technical Preview has shipped; Chrome has a flagged implementation.
Testing: Tested through our tests as well as the ECMAScript standard test suite test262.


[1]: https://github.com/tc39/proposal-array-from-async

-- Matthew Gaudet
Reply all
Reply to author
Forward
0 new messages