@@ -234,6 +234,7 @@ const d = await Data.fromAsync(asyncGen(4));
234234### Optional parameters
235235Array.fromAsync has two optional parameters: ` mapfn` and ` thisArg` .
236236
237+ #### Mapping function
237238` mapfn` is an optional mapping callback, which is called on each value yielded from the input,
238239along with its index integer (starting from 0).
239240Each 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,
263264but ` Array .fromAsync (input, x => x)` will resolve them
264265because the result of the ` x => x` mapping function is awaited.
265266
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
266294` thisArg` is a ` this ` -binding receiver value for the mapping callback. By
267295default, this is undefined. These optional parameters match the behavior of
268296Array.from. Their exclusion would be surprising to developers who are already
0 commit comments