Skip to content

Instantly share code, notes, and snippets.

@TooTallNate
Created December 11, 2012 18:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TooTallNate/7ddb4551bd941e84b104 to your computer and use it in GitHub Desktop.
Save TooTallNate/7ddb4551bd941e84b104 to your computer and use it in GitHub Desktop.
readable.js: implicit _read() call when "lowWaterMark" is greater than 0
diff --git a/readable.js b/readable.js
index 3e9253a..b10daa8 100644
--- a/readable.js
+++ b/readable.js
@@ -104,6 +104,21 @@ function Readable(options) {
this.readable = true;
Stream.apply(this);
+
+ if (this._readableState.lowWaterMark != 0) {
+ // we probably need an implicit _read() call. have to nextTick it in
+ // case the _read function gets defined after this Readable gets returned
+ process.nextTick(checkRead(this));
+ }
+}
+
+function checkRead(readable) {
+ var state = readable._readableState;
+ return function() {
+ if (state.length < state.lowWaterMark) {
+ readable.read(0);
+ }
+ };
}
// backwards compatibility.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment