Skip to content

Commit

Permalink
fix: Update explainer to not await values twice
Browse files Browse the repository at this point in the history
  • Loading branch information
js-choi committed Jul 17, 2022
1 parent 49d651d commit 541f23d
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 @@ -30,8 +30,8 @@ This of course does **not** include any code
that uses ad-hoc `for await``of` loops with empty arrays:
```js
const arr = [];
for await (const item of asyncItems) {
arr.push(await item);
for await (const v of asyncIterable) {
arr.push(v);
}
```
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(await v);
arr.push(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(await v);
arr.push(v);
}

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

// This is equivalent.
Expand Down

0 comments on commit 541f23d

Please sign in to comment.