Skip to content

Commit 15ed9ce

Browse files
committed
explainer/spec: mapfn may be async
See #4.
1 parent d32077c commit 15ed9ce

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

README.md

+13-4
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,19 @@ await Array.fromAsync(f());
5959

6060
[`Array.from`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from
6161

62-
`mapfn` is an optional function to call on every item value,
63-
and `thisArg` is an optional value to (or `undefined` by default).
64-
65-
Also similarly to `Array.from`, `Array.fromAsync` is a **generic factory method**.
62+
`mapfn` is an optional function to call on every item value.
63+
(Unlike `Array.from`, `mapfn` may be an **async function**.
64+
Whenever `mapfn` returns a promise, that promise will be awaited,
65+
and the value it resolves to is what is added
66+
to the final returned promise’s array.
67+
If `mapfn`’s promise rejects,
68+
then the final returned promise
69+
will also reject with that error.)
70+
71+
`thisArg` is an optional value with which to call `mapfn`
72+
(or `undefined` by default).
73+
74+
Like `Array.from`, `Array.fromAsync` is a **generic factory method**.
6675
It does not require that its `this` value be the `Array` constructor,
6776
and it can be transferred to or inherited by any other constructors
6877
that may be called with a single numeric argument.

spec.html

+3-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ <h1><ins>Array.fromAsync ( _asyncItems_ [ , _mapfn_ [ , _thisArg_ ] ] )</ins></h
6969
1. Let _nextValue_ be ? IteratorValue(_next_).
7070
1. If _mapping_ is *true*, then
7171
1. Let _mappedValue_ be Call(_mapfn_, _thisArg_, &laquo; _nextValue_, 𝔽(_k_) &raquo;).
72-
1. If _mappedValue_ is an abrupt completion, return ? AsyncIteratorClose(_iteratorRecord_, _mappedValue_).
72+
1. IfAbruptCloseAsyncIterator(_iteratorRecord_, _mappedValue_).
73+
1. Let _mappedValue_ to Await(_mappedValue_).
74+
1. IfAbruptCloseAsyncIterator(_iteratorRecord_, _mappedValue_).
7375
1. Set _mappedValue_ to _mappedValue_.[[Value]].
7476
1. Else, let _mappedValue_ be _nextValue_.
7577
1. Let _defineStatus_ be CreateDataPropertyOrThrow(_A_, _Pk_, _mappedValue_).

0 commit comments

Comments
 (0)