Permalink
Browse files

Force transform callback to be called on nextTick

  • Loading branch information...
1 parent 97a9fff commit bab9ff42da59d17446fc04bc24a2ecae9722f85f @isaacs isaacs committed Oct 2, 2012
Showing with 9 additions and 2 deletions.
  1. +1 −1 readable.js
  2. +8 −1 transform.js
View
@@ -26,7 +26,7 @@ function ReadableState(options, stream) {
this.stream = stream;
this.reading = false;
- // whenever we return false, then we set a flag to say
+ // whenever we return null, then we set a flag to say
// that we're awaiting a 'readable' event emission.
this.needReadable = false;
}
View
@@ -58,7 +58,14 @@ Transform.prototype._transform = function(chunk, output, cb) {
Transform.prototype._write = function(chunk, cb) {
- this._transform(chunk, this._output, 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);
+ });
+ });
};
Transform.prototype._read = function(n, cb) {

0 comments on commit bab9ff4

Please sign in to comment.