Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

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

Closed
Satyam opened this issue Jul 3, 2012 · 4 comments
Closed

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

Satyam opened this issue Jul 3, 2012 · 4 comments
Labels

Comments

@Satyam
Copy link

Satyam commented Jul 3, 2012

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.

@daviddias
Copy link

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

@Satyam
Copy link
Author

Satyam commented Jan 22, 2014

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.

@daviddias
Copy link

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

@jimlloyd
Copy link

jimlloyd commented Sep 8, 2014

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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants