From dbcacc5afe4c1fea4a0796d95090ea6aff7e67ed Mon Sep 17 00:00:00 2001 From: isaacs Date: Tue, 4 Dec 2012 18:19:07 -0800 Subject: [PATCH] streams2: NextTick the emit('readable') in resume() Otherwise resume() will cause data to be emitted before it can be handled. --- lib/_stream_readable.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js index 6c4d95e5b..54ceaa102 100644 --- a/lib/_stream_readable.js +++ b/lib/_stream_readable.js @@ -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.