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.
This commit is contained in:
parent
4231dab39f
commit
e03bc472f0
@ -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);
|
||||
};
|
||||
|
@ -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) {
|
||||
|
@ -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…
x
Reference in New Issue
Block a user