Skip to content

Commit facec4c

Browse files
authored
Revert #20 and do not await async inputs’ values without mapping ƒ (#27)
1 parent b1e0b7a commit facec4c

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

README.md

+9-5
Original file line numberDiff line numberDiff line change
@@ -219,11 +219,15 @@ const d = await Data.fromAsync(asyncGen(4));
219219
### Optional parameters
220220
Array.fromAsync has two optional parameters: `mapfn` and `thisArg`.
221221

222-
`mapfn` is a mapping callback, which is called on each value yielded from the
223-
input (and awaited if it came from a synchronous input), along with its index
224-
integer (starting from 0). Each result of the mapping callback is, in turn,
225-
awaited then added to the array. By default, the callback is essentially an
226-
identity function.
222+
`mapfn` is an optional mapping callback, which is called on each value yielded
223+
from the input (and awaited if it came from a synchronous input), along with
224+
its index integer (starting from 0). Each result of the mapping callback is, in
225+
turn, awaited then added to the array.
226+
227+
(Without the optional mapping callback, each value yielded from asynchronous
228+
inputs is not awaited, and each value yielded from synchronous inputs is
229+
awaited only once, before the value is added to the result array. This matches
230+
the behavior of `for await`.)
227231

228232
`thisArg` is a `this`-binding receiver value for the mapping callback. By
229233
default, this is undefined. These optional parameters match the behavior of

spec.html

+3-4
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,10 @@ <h1><ins>Array.fromAsync ( _asyncItems_ [ , _mapfn_ [ , _thisArg_ ] ] )</ins></h
144144
1. Let _nextValue_ be ? IteratorValue(_next_).
145145
1. If _mapping_ is *true*, then
146146
1. Let _mappedValue_ be Call(_mapfn_, _thisArg_, &laquo; _nextValue_, 𝔽(_k_) &raquo;).
147-
1. IfAbruptCloseAsyncIterator(_iteratorRecord_, _mappedValue_).
147+
1. IfAbruptCloseAsyncIterator(_mappedValue_, _iteratorRecord_).
148+
1. Set _mappedValue_ to Await(_mappedValue_).
149+
1. IfAbruptCloseAsyncIterator(_mappedValue_, _iteratorRecord_).
148150
1. Else, let _mappedValue_ be _nextValue_.
149-
1. Set _mappedValue_ to Await(_mappedValue_).
150-
1. IfAbruptCloseAsyncIterator(_iteratorRecord_, _mappedValue_).
151-
1. Set _mappedValue_ to _mappedValue_.[[Value]].
152151
1. Let _defineStatus_ be CreateDataPropertyOrThrow(_A_, _Pk_, _mappedValue_).
153152
1. If _defineStatus_ is an abrupt completion, return ? AsyncIteratorClose(_iteratorRecord_, _defineStatus_).
154153
1. Set _k_ to _k_ + 1.

0 commit comments

Comments
 (0)