Browse Source

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.
v0.9.11-release
isaacs 12 years ago
parent
commit
e03bc472f0
  1. 8
      lib/_stream_readable.js
  2. 5
      lib/_stream_transform.js
  3. 6
      lib/_stream_writable.js

8
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);
};

5
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) {

6
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

Loading…
Cancel
Save