Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Method pause() on ReadLine should pause 'line' events #3628

Closed
Satyam opened this Issue · 4 comments

3 participants

Daniel Barreiro David Dias Jim Lloyd
Daniel Barreiro

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.

David Dias
Owner

@Satyam , streams have changed meantime, could you confirm if this is still an issue? Thank you

Daniel Barreiro

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.

David Dias
Owner

Thank you @Satyam , if you run on it again, please inform us, I'll close it for now.

David Dias diasdavid closed this
Jim Lloyd

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.