Skip to content

Commit

Permalink
Revert #20 and do not await async inputs’ values without mapping ƒ (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
js-choi authored Jul 12, 2022
1 parent b1e0b7a commit facec4c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,15 @@ const d = await Data.fromAsync(asyncGen(4));
### Optional parameters
Array.fromAsync has two optional parameters: `mapfn` and `thisArg`.

`mapfn` is a mapping callback, which is called on each value yielded from the
input (and awaited if it came from a synchronous input), along with its index
integer (starting from 0). Each result of the mapping callback is, in turn,
awaited then added to the array. By default, the callback is essentially an
identity function.
`mapfn` is an optional mapping callback, which is called on each value yielded
from the input (and awaited if it came from a synchronous input), along with
its index integer (starting from 0). Each result of the mapping callback is, in
turn, awaited then added to the array.

(Without the optional mapping callback, each value yielded from asynchronous
inputs is not awaited, and each value yielded from synchronous inputs is
awaited only once, before the value is added to the result array. This matches
the behavior of `for await`.)

`thisArg` is a `this`-binding receiver value for the mapping callback. By
default, this is undefined. These optional parameters match the behavior of
Expand Down
7 changes: 3 additions & 4 deletions spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,10 @@ <h1><ins>Array.fromAsync ( _asyncItems_ [ , _mapfn_ [ , _thisArg_ ] ] )</ins></h
1. Let _nextValue_ be ? IteratorValue(_next_).
1. If _mapping_ is *true*, then
1. Let _mappedValue_ be Call(_mapfn_, _thisArg_, &laquo; _nextValue_, 𝔽(_k_) &raquo;).
1. IfAbruptCloseAsyncIterator(_iteratorRecord_, _mappedValue_).
1. IfAbruptCloseAsyncIterator(_mappedValue_, _iteratorRecord_).
1. Set _mappedValue_ to Await(_mappedValue_).
1. IfAbruptCloseAsyncIterator(_mappedValue_, _iteratorRecord_).
1. Else, let _mappedValue_ be _nextValue_.
1. Set _mappedValue_ to Await(_mappedValue_).
1. IfAbruptCloseAsyncIterator(_iteratorRecord_, _mappedValue_).
1. Set _mappedValue_ to _mappedValue_.[[Value]].
1. Let _defineStatus_ be CreateDataPropertyOrThrow(_A_, _Pk_, _mappedValue_).
1. If _defineStatus_ is an abrupt completion, return ? AsyncIteratorClose(_iteratorRecord_, _defineStatus_).
1. Set _k_ to _k_ + 1.
Expand Down

0 comments on commit facec4c

Please sign in to comment.