streams2: NextTick the emit('readable') in resume()

Otherwise resume() will cause data to be emitted before it can be handled.
This commit is contained in:
isaacs
2012-12-04 18:19:07 -08:00
parent 99021b7a4f
commit dbcacc5afe

View File

@@ -545,6 +545,7 @@ function emitDataEvents(stream, startPaused) {
stream.on('readable', function() {
readable = true;
var c;
while (!paused && (null !== (c = stream.read())))
stream.emit('data', c);
@@ -562,7 +563,9 @@ function emitDataEvents(stream, startPaused) {
stream.resume = function() {
paused = false;
if (readable)
stream.emit('readable');
process.nextTick(function() {
stream.emit('readable');
});
};
// now make it start, just in case it hadn't already.