GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — doc: add caveat and tradeoff example to readline · nodejs/node@2ee9a96

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • doc/api
    • readline.md
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎doc/api/readline.md‎

Copy file name to clipboardExpand all lines: doc/api/readline.md
+28Lines changed: 28 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,34 @@ rl.on('line', (line) => {
597597
});
598598
```
599599

600+
Currently, `for`-`await`-`of` loop can be a bit slower. If `async` / `await`
601+
flow and speed are both essential, a mixed approach can be applied:
602+
603+
```js
604+
const { once } = require('events');
605+
const { createReadStream } = require('fs');
606+
const { createInterface } = require('readline');
607+
608+
(async function processLineByLine() {
609+
try {
610+
const rl = createInterface({
611+
input: createReadStream('big-file.txt'),
612+
crlfDelay: Infinity
613+
});
614+
615+
rl.on('line', (line) => {
616+
// Process the line.
617+
});
618+
619+
await once(rl, 'close');
620+
621+
console.log('File processed.');
622+
} catch (err) {
623+
console.error(err);
624+
}
625+
})();
626+
```
627+
600628
[`'SIGCONT'`]: readline.html#readline_event_sigcont
601629
[`'SIGTSTP'`]: readline.html#readline_event_sigtstp
602630
[`'line'`]: #readline_event_line

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.