File tree 1 file changed +35
-0
lines changed
1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -60,3 +60,38 @@ This proposal introduces two new intrisic objects, in addition to the two added
60
60
const AsyncIteratorHelperPrototype = Object .getPrototypeOf (AsyncIterator .from ([]).take (0 ));
61
61
const WrapForValidAsyncIteratorPrototype = Object .getPrototypeOf (AsyncIterator .from ({ async next (){} }));
62
62
```
63
+
64
+ ## More Example Usage
65
+
66
+ ### Lazy Iteration over sets
67
+
68
+ Iterating over a set of URLs, asynchronously fetching each, and returning an array of their
69
+ JSON Output.
70
+
71
+ ``` js
72
+ const responses = await AsyncIterator .from (urls)
73
+ .map (async (url ) => {
74
+ const response = await fetch (url);
75
+ return response .json ();
76
+ })
77
+ .toArray ();
78
+ ```
79
+
80
+ Example of iterating over a potentially infinite iterator and transforming it to an array in groups
81
+ of 5.
82
+
83
+ ``` js
84
+ class ObligatoryCryptocurrencyReference extends Component {
85
+ componentWillMount () {
86
+ const items = ticker () // returns async iterator
87
+ .map ((c ) => createElement (' h2' , null , ` ${ c .name } : ${ c .price } ` ))
88
+ .take (5 ) // only consume 5 items of a potentially infinite iterator
89
+ .toArray () // greedily transform async iterator into array
90
+ .then ((data ) => this .setState ({ data }));
91
+ }
92
+
93
+ render () {
94
+ return createElement (' div' , null , this .state .data );
95
+ }
96
+ }
97
+ ```
You can’t perform that action at this time.
0 commit comments