Skip to content
Closed
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
doc: add caveat and tradeoff example to readline
Refs: #23916
  • Loading branch information
vsemozhetbyt committed Mar 6, 2019
commit 67d2f8d5d26de6e1621b5239b37db9f46730e8ad
28 changes: 28 additions & 0 deletions doc/api/readline.md
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,34 @@ rl.on('line', (line) => {
});
```

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
const { once } = require('events');
const { createReadStream } = require('fs');
const { createInterface } = require('readline');

(async function processLineByLine() {
try {
const rl = createInterface({
input: createReadStream('big-file.txt'),
crlfDelay: Infinity
});

rl.on('line', (line) => {
// Process the line.
});

await once(rl, 'close');

console.log('File processed.');
} catch (err) {
console.error(err);
}
})();
```

[`'SIGCONT'`]: readline.html#readline_event_sigcont
[`'SIGTSTP'`]: readline.html#readline_event_sigtstp
[`'line'`]: #readline_event_line
Expand Down