Is There A Way To Actually Pause Readline?
Solution 1:
This is a limitation of how the readline
module works in NodeJS. It pauses reading the input but does not do so immediately. This is in part because of what Node streams were designed to do.
pause
and resume
were meant to handle backpressure - which means their goal was to deal with producers which were "too fast" for their consumers to keep up with and in order to balance node. They were never designed in the context of guaranteeing things pausing immediately.
You can use lower level fs
operations instead and reading the lines one by one or storing them in a buffer to overcome this. If the file is small enough - just doing fs.readFile
on it and splitting by \n
should probably be enough to then iterate it with promises and perform async actions.
Post a Comment for "Is There A Way To Actually Pause Readline?"