From e03bc472f0b4a50ede3a0e0be7de9e5d12bb85a9 Mon Sep 17 00:00:00 2001 From: isaacs Date: Fri, 22 Feb 2013 16:45:22 -0800 Subject: stream: Start out in sync=true state The Readable and Writable classes will nextTick certain things if in sync mode. The sync flag gets unset after a call to _read or _write. However, most of these behaviors should also be deferred until nextTick if no reads have been made (for example, the automatic '_read up to hwm' behavior on Readable.push(chunk)) Set the sync flag to true in the constructor, so that it will not trigger an immediate 'readable' event, call to _read, before the user has had a chance to set a _read method implementation. --- lib/_stream_transform.js | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'lib/_stream_transform.js') diff --git a/lib/_stream_transform.js b/lib/_stream_transform.js index b83fedb62..0ee5a5030 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) { -- cgit v1.2.1