diff options
-rw-r--r-- | lib/_stream_readable.js | 8 | ||||
-rw-r--r-- | lib/_stream_transform.js | 5 | ||||
-rw-r--r-- | lib/_stream_writable.js | 6 |
3 files changed, 16 insertions, 3 deletions
diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js index 2d67bb22fe..a78cd40aab 100644 --- a/lib/_stream_readable.js +++ b/lib/_stream_readable.js @@ -51,7 +51,13 @@ function ReadableState(options, stream) { this.ended = false; this.endEmitted = false; this.reading = false; - this.sync = false; + + // a flag to be able to tell if the onwrite cb is called immediately, + // or on a later tick. We set this to true at first, becuase any + // actions that shouldn't happen until "later" should generally also + // not happen before the first write call. + this.sync = true; + this.onread = function(er, data) { onread(stream, er, data); }; diff --git a/lib/_stream_transform.js b/lib/_stream_transform.js index b83fedb626..0ee5a5030e 100644 --- a/lib/_stream_transform.js +++ b/lib/_stream_transform.js @@ -125,6 +125,11 @@ function Transform(options) { // start out asking for a readable event once data is transformed. this._readableState.needReadable = true; + // we have implemented the _read method, and done the other things + // that Readable wants before the first _read call, so unset the + // sync guard flag. + this._readableState.sync = false; + this.once('finish', function() { if ('function' === typeof this._flush) this._flush(ts.output, function(er) { diff --git a/lib/_stream_writable.js b/lib/_stream_writable.js index 9fe4c85bd3..d3b5d7494d 100644 --- a/lib/_stream_writable.js +++ b/lib/_stream_writable.js @@ -73,8 +73,10 @@ function WritableState(options, stream) { this.writing = false; // a flag to be able to tell if the onwrite cb is called immediately, - // or on a later tick. - this.sync = false; + // or on a later tick. We set this to true at first, becuase any + // actions that shouldn't happen until "later" should generally also + // not happen before the first write call. + this.sync = true; // a flag to know if we're processing previously buffered items, which // may call the _write() callback in the same tick, so that we don't |