File tree 1 file changed +28
-0
lines changed
1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -597,6 +597,34 @@ rl.on('line', (line) => {
597
597
});
598
598
```
599
599
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
+
600
628
[ `'SIGCONT'` ] : readline.html#readline_event_sigcont
601
629
[ `'SIGTSTP'` ] : readline.html#readline_event_sigtstp
602
630
[ `'line'` ] : #readline_event_line
You can’t perform that action at this time.
0 commit comments