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 @@ -534,6 +534,34 @@ rl.on('line', (line) => {
534
534
});
535
535
```
536
536
537
+ Currently, ` for ` -` await ` -` of ` loop can be a bit slower. If ` async ` / ` await `
538
+ flow and speed are both essential, a mixed approach can be applied:
539
+
540
+ ``` js
541
+ const { once } = require (' events' );
542
+ const { createReadStream } = require (' fs' );
543
+ const { createInterface } = require (' readline' );
544
+
545
+ (async function processLineByLine () {
546
+ try {
547
+ const rl = createInterface ({
548
+ input: createReadStream (' big-file.txt' ),
549
+ crlfDelay: Infinity
550
+ });
551
+
552
+ rl .on (' line' , (line ) => {
553
+ // Process the line.
554
+ });
555
+
556
+ await once (rl, ' close' );
557
+
558
+ console .log (' File processed.' );
559
+ } catch (err) {
560
+ console .error (err);
561
+ }
562
+ })();
563
+ ```
564
+
537
565
[ `'SIGCONT'` ] : readline.html#readline_event_sigcont
538
566
[ `'SIGTSTP'` ] : readline.html#readline_event_sigtstp
539
567
[ `process.stdin` ] : process.html#process_process_stdin
You can’t perform that action at this time.
0 commit comments