@@ -17,23 +17,37 @@ Since its standardization in JavaScript, **[Array.from][]** has become one of
17
17
` Array ` ’s most frequently used built-in methods. However, no similar
18
18
functionality exists for async iterators.
19
19
20
+ ``` js
21
+ const arr = [];
22
+ for (const v of iterable) {
23
+ arr .push (v);
24
+ }
25
+
26
+ // This does the same thing.
27
+ const arr = Array .from (iterable);
28
+ ```
29
+
20
30
[ Array.from ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from
21
31
22
- Such functionality would be useful for ** dumping** the entirety of an ** async
23
- iterator** into a ** single data structure** , especially in ** unit tests ** or in
24
- ** command-line** interfaces. (Several real-world examples are included in a
25
- following section.)
32
+ Such functionality would also be useful for ** dumping** the entirety of an
33
+ ** async iterator** into a ** single data structure** , especially in ** unit
34
+ tests ** or in ** command-line** interfaces. (Several real-world examples are
35
+ included in a following section.)
26
36
27
- There is an [ it-all] [ ] NPM library that performs only this task
28
- and which gets about 50,000 weekly downloads daily.
29
- This of course does ** not** include any code
30
- that uses ad-hoc ` for await ` –` of ` loops with empty arrays:
31
37
``` js
32
38
const arr = [];
33
39
for await (const v of asyncIterable ) {
34
40
arr .push (v);
35
41
}
42
+
43
+ // We should add something that does the same thing.
44
+ const arr = await ?????????? (asyncIterable);
36
45
` ` `
46
+
47
+ There is an [it-all][] NPM library that performs only this task
48
+ and which gets about 50,000 weekly downloads daily.
49
+ This of course does **not** include any code
50
+ that uses ad-hoc ` for await ` –` of ` loops with empty arrays.
37
51
Further demonstrating the demand for such functionality,
38
52
several [Stack Overflow questions][Stack Overflow] have been asked
39
53
by various developers, asking how to convert async iterators to arrays.
@@ -47,8 +61,8 @@ later in this explainer.
47
61
## Description
48
62
(A [formal draft specification][specification] is available.)
49
63
50
- Array.fromAsync is to ` for await ` \
51
- as Array.from is to ` for ` .
64
+ ** Array.fromAsync is to ` for await ` ** \
65
+ as ** Array.from is to ` for ` .**
52
66
53
67
Similarly to [Array.from][], Array.fromAsync would be a static method of the
54
68
` Array ` built-in class, with one required argument and two optional arguments:
0 commit comments