Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert #20 and do not await async inputs’ values without mapping ƒ #27

Merged
merged 3 commits into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
6 changes: 3 additions & 3 deletions spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ <h1><ins>Array.fromAsync ( _asyncItems_ [ , _mapfn_ [ , _thisArg_ ] ] )</ins></h
1. If _mapping_ is *true*, then
1. Let _mappedValue_ be Call(_mapfn_, _thisArg_, &laquo; _nextValue_, 𝔽(_k_) &raquo;).
1. IfAbruptCloseAsyncIterator(_iteratorRecord_, _mappedValue_).
1. Set _mappedValue_ to Await(_mappedValue_).
1. IfAbruptCloseAsyncIterator(_iteratorRecord_, _mappedValue_).
js-choi marked this conversation as resolved.
Show resolved Hide resolved
1. Set _mappedValue_ to _mappedValue_.[[Value]].
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IfAbruptCloseAsyncIterator already does this. (It's a macro.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be clear, is the suggestion to remove all three of the highlighted lines? I’m rechecking the definition of IfAbruptCloseAsyncIterator, and it does seem to take care of unwrapping mappedValue into its [[Value]]—but I don’t see where it Awaits mappedValue beforehand.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just the Set _mappedValue_ to _mappedValue_.[[Value]] line specifically, sorry.

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