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

doc: update readline asyncIterator docs #28425

Merged
merged 2 commits into from
Jun 27, 2019
Merged
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
14 changes: 5 additions & 9 deletions doc/api/readline.md
Original file line number Diff line number Diff line change
Expand Up @@ -318,24 +318,20 @@ changes:
description: Symbol.asyncIterator support is no longer experimental.
-->

> Stability: 2 - Stable

* Returns: {AsyncIterator}

Create an `AsyncIterator` object that iterates through each line in the input
stream as a string. This method allows asynchronous iteration of
`readline.Interface` objects through `for`-`await`-`of` loops.
`readline.Interface` objects through `for await...of` loops.
cjihrig marked this conversation as resolved.
Show resolved Hide resolved

Errors in the input stream are not forwarded.

If the loop is terminated with `break`, `throw`, or `return`,
[`rl.close()`][] will be called. In other words, iterating over a
`readline.Interface` will always consume the input stream fully.

A caveat with using this experimental API is that the performance is
currently not on par with the traditional `'line'` event API, and thus it is
not recommended for performance-sensitive applications. We expect this
situation to improve in the future.
Performance is not on par with the traditional `'line'` event API. Use `'line'`
instead for performance-sensitive applications.

```js
async function processLineByLine() {
Expand Down Expand Up @@ -560,7 +556,7 @@ rl.on('line', (line) => {

A common use case for `readline` is to consume an input file one line at a
time. The easiest way to do so is leveraging the [`fs.ReadStream`][] API as
well as a `for`-`await`-`of` loop:
well as a `for await...of` loop:

```js
const fs = require('fs');
Expand Down Expand Up @@ -601,7 +597,7 @@ rl.on('line', (line) => {
});
```

Currently, `for`-`await`-`of` loop can be a bit slower. If `async` / `await`
Currently, `for await...of` loop can be a bit slower. If `async` / `await`
flow and speed are both essential, a mixed approach can be applied:

```js
Expand Down