@@ -234,6 +234,7 @@ const d = await Data.fromAsync(asyncGen(4));
234
234
### Optional parameters
235
235
Array.fromAsync has two optional parameters: ` mapfn` and ` thisArg` .
236
236
237
+ #### Mapping function
237
238
` mapfn` is an optional mapping callback, which is called on each value yielded from the input,
238
239
along with its index integer (starting from 0).
239
240
Each result of the mapping callback is, in turn, awaited then added to the array.
@@ -263,6 +264,33 @@ This is because, whenever input is an async iterable that yields promise items,
263
264
but ` Array .fromAsync (input, x => x)` will resolve them
264
265
because the result of the ` x => x` mapping function is awaited.
265
266
267
+ For example:
268
+
269
+ ` ` ` js
270
+ function as () {
271
+ return {
272
+ [Symbol .asyncIterator ]() {
273
+ return {
274
+ async next () {
275
+ if (i > 2 ) return { done: true };
276
+ i++ ;
277
+ return { value: Promise .resolve (i), done: false }
278
+ }
279
+ }
280
+ }
281
+ };
282
+ }
283
+
284
+ // This prints `[Promise.resolve(1), Promise.resolve(2), Promise.resolve(3)]`:
285
+ console .log (await Array .fromAsync (it));
286
+
287
+ // This prints `[1, 2, 3]`:
288
+ console .log (await Array .fromAsync (it, x => x));
289
+ ` ` `
290
+
291
+ See also [issue #19](https://github.com/tc39/proposal-array-from-async/issues/19).
292
+
293
+ #### ` this ` argument
266
294
` thisArg` is a ` this ` -binding receiver value for the mapping callback. By
267
295
default, this is undefined. These optional parameters match the behavior of
268
296
Array.from. Their exclusion would be surprising to developers who are already
0 commit comments