Skip to content
Browse files

transform/writable: Just nextTick the drain emission, not the whole cb

  • Loading branch information...
1 parent 59dc83b commit 0f8f4f7c22743712cf8630d9e6ecad12a6008a7f @isaacs isaacs committed Oct 2, 2012
Showing with 10 additions and 10 deletions.
  1. +1 −8 transform.js
  2. +9 −2 writable.js
View
9 transform.js
@@ -58,14 +58,7 @@ Transform.prototype._transform = function(chunk, output, cb) {
Transform.prototype._write = function(chunk, cb) {
- // Must force callback to be called on nextTick, so that we don't
- // emit 'drain' before the write() consumer gets the 'false' return
- // value, and has a chance to attach a 'drain' listener.
- this._transform(chunk, this._output, function(er) {
- process.nextTick(function() {
- cb(er);
- });
- });
+ this._transform(chunk, this._output, cb);
};
Transform.prototype._read = function(n, cb) {
View
11 writable.js
@@ -85,8 +85,15 @@ Writable.prototype.write = function(chunk, encoding) {
}
if (state.length < state.lowWaterMark && state.needDrain) {
- state.needDrain = false;
- this.emit('drain');
+ // Must force callback to be called on nextTick, so that we don't
+ // emit 'drain' before the write() consumer gets the 'false' return
+ // value, and has a chance to attach a 'drain' listener.
+ process.nextTick(function() {
+ if (!state.needDrain)
+ return;
+ state.needDrain = false;
+ this.emit('drain');
+ }.bind(this));
}
}.bind(this));

0 comments on commit 0f8f4f7

Please sign in to comment.
Something went wrong with that request. Please try again.