Created
February 22, 2013 19:15
-
-
Save isaacs/5015824 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js | |
index ff4bf40..2d67bb2 100644 | |
--- a/lib/_stream_readable.js | |
+++ b/lib/_stream_readable.js | |
@@ -329,6 +329,12 @@ function onread(stream, er, chunk) { | |
if (state.needReadable) | |
emitReadable(stream); | |
+ else if (state.sync) | |
+ process.nextTick(function() { | |
+ maybeReadMore(stream, state); | |
+ }); | |
+ else | |
+ maybeReadMore(stream, state); | |
} | |
// Don't emit readable right away in sync mode, because this can trigger | |
@@ -352,7 +358,10 @@ function emitReadable(stream) { | |
function emitReadable_(stream) { | |
var state = stream._readableState; | |
stream.emit('readable'); | |
+ maybeReadMore(stream, state); | |
+} | |
+function maybeReadMore(stream, state) { | |
// at this point, the user has presumably seen the 'readable' event, | |
// and called read() to consume some data. that may have triggered | |
// in turn another _read(n,cb) call, in which case reading = true if | |
diff --git a/test/simple/test-stream2-basic.js b/test/simple/test-stream2-basic.js | |
index bc4ca53..4dc4766 100644 | |
--- a/test/simple/test-stream2-basic.js | |
+++ b/test/simple/test-stream2-basic.js | |
@@ -334,13 +334,13 @@ test('back pressure respected', function (t) { | |
function noop() {} | |
var r = new R(); | |
+ r._read = noop; | |
var counter = 0; | |
r.push(["one"]); | |
r.push(["two"]); | |
r.push(["three"]); | |
r.push(["four"]); | |
r.push(null); | |
- r._read = noop; | |
var w1 = new R(); | |
w1.write = function (chunk) { | |
diff --git a/test/simple/test-stream2-objects.js b/test/simple/test-stream2-objects.js | |
index 6c1e739..5087cb0 100644 | |
--- a/test/simple/test-stream2-objects.js | |
+++ b/test/simple/test-stream2-objects.js | |
@@ -75,11 +75,11 @@ function toArray(callback) { | |
function fromArray(list) { | |
var r = new Readable(); | |
+ r._read = noop; | |
list.forEach(function(chunk) { | |
r.push(chunk); | |
}); | |
r.push(null); | |
- r._read = noop; | |
return r; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment