Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

add (corrected) for-await-of equivalent example #129

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
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
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ for await (const line of readLines(filePath)) {
}
```

This is equivalent to:

```js
const i = readLines(filePath);
while (true) {
const {value, done} = await i.next();
if (done) break;
console.log(value);
}
```

Async for-of statements are only allowed within async functions and async generator functions (see below for the latter).

During execution, an async iterator is created from the data source using the `[Symbol.asyncIterator]()` method.
Expand Down