You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.
The pause() and resume() methods should not only affect the ReadStream but also the emission of 'line' events, which is what you want to actually pause since that is the whole point of using ReadLine. As it stands, when you pause the ReadLine instance, 'line' events keep on coming until the array of lines is emptied.
The text was updated successfully, but these errors were encountered:
I'm sorry, I don't even remember where or why I used that feature. That was two years ago and somehow I got by. Should I close this issue? As far as I am concerned, it is no longer an issue, not for me.
I believe this issue still exists with node v0.10 (I am currently using v0.10.29).
The problem is that it doesn't seem possible to use either readline or repl to process one line at a time when input is piped from a file. To demonstrate the problem, use this slightly revised example from http://nodejs.org/api/readline.html#readline_example_tiny_cli:
#!/usr/bin/env node
'use strict';
var readline = require('readline'),
rl = readline.createInterface(process.stdin, process.stdout);
rl.setPrompt('OHAI> ');
rl.prompt();
rl.on('line', function(line) {
rl.pause();
function onetime() {
switch(line.trim()) {
case 'hello':
console.log('world!');
break;
default:
console.log('Say what? I might have heard ' + line.trim() + '');
break;
}
rl.prompt();
}
// setImmediate(onetime);
onetime();
}).on('close', function() {
console.log('Have a great day!');
process.exit(0);
});
Run the above script redirecting a file to stdin. Then comment out the call to onetime() and uncomment the line immediately above it that defers the call to onetime to the next tick. Note that the call to rl.pause() did nothing to throttle the data.
The pause() and resume() methods should not only affect the ReadStream but also the emission of 'line' events, which is what you want to actually pause since that is the whole point of using ReadLine. As it stands, when you pause the ReadLine instance, 'line' events keep on coming until the array of lines is emptied.
The text was updated successfully, but these errors were encountered: