Skip to content

Commit

Permalink
Clarify that values from async inputs are awaited when callback omitted
Browse files Browse the repository at this point in the history
See #29, #20, and #23.
  • Loading branch information
js-choi committed Jan 24, 2022
1 parent cf49c0c commit f540775
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ that uses ad-hoc `for await`–`of` loops with empty arrays:
```js
const arr = [];
for await (const item of asyncItems) {
arr.push(item);
arr.push(await item);
}
```
Further demonstrating the demand for such functionality,
Expand Down Expand Up @@ -71,7 +71,7 @@ async function * asyncGen (n) {
// `arr` will be `[0, 2, 4, 6]`.
const arr = [];
for await (const v of asyncGen(4)) {
arr.push(v);
arr.push(await v);
}

// This is equivalent.
Expand All @@ -96,7 +96,7 @@ function * genPromises (n) {
// `arr` will be `[ 0, 2, 4, 6 ]`.
const arr = [];
for await (const v of genPromises(4)) {
arr.push(v);
arr.push(await v);
}

// This is equivalent.
Expand Down Expand Up @@ -174,7 +174,7 @@ const arrLike = {
// `arr` will be `[ 0, 2, 4, 6 ]`.
const arr = [];
for await (const v of Array.from(arrLike)) {
arr.push(v);
arr.push(await v);
}

// This is equivalent.
Expand Down Expand Up @@ -239,7 +239,7 @@ async function * asyncGen (n) {
// `arr` will be `[ 0, 4, 16, 36 ]`.
const arr = [];
for await (const v of asyncGen(4)) {
arr.push(v ** 2);
arr.push(await (v ** 2));
}

// This is equivalent.
Expand Down

0 comments on commit f540775

Please sign in to comment.