Skip to content

Commit f540775

Browse files
committed
Clarify that values from async inputs are awaited when callback omitted
See #29, #20, and #23.
1 parent cf49c0c commit f540775

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ that uses ad-hoc `for await`–`of` loops with empty arrays:
3131
```js
3232
const arr = [];
3333
for await (const item of asyncItems) {
34-
arr.push(item);
34+
arr.push(await item);
3535
}
3636
```
3737
Further demonstrating the demand for such functionality,
@@ -71,7 +71,7 @@ async function * asyncGen (n) {
7171
// `arr` will be `[0, 2, 4, 6]`.
7272
const arr = [];
7373
for await (const v of asyncGen(4)) {
74-
arr.push(v);
74+
arr.push(await v);
7575
}
7676

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

102102
// This is equivalent.
@@ -174,7 +174,7 @@ const arrLike = {
174174
// `arr` will be `[ 0, 2, 4, 6 ]`.
175175
const arr = [];
176176
for await (const v of Array.from(arrLike)) {
177-
arr.push(v);
177+
arr.push(await v);
178178
}
179179

180180
// This is equivalent.
@@ -239,7 +239,7 @@ async function * asyncGen (n) {
239239
// `arr` will be `[ 0, 4, 16, 36 ]`.
240240
const arr = [];
241241
for await (const v of asyncGen(4)) {
242-
arr.push(v ** 2);
242+
arr.push(await (v ** 2));
243243
}
244244

245245
// This is equivalent.

0 commit comments

Comments
 (0)