mirror of
https://github.com/nodejs/node-v0.x-archive.git
synced 2026-04-28 03:01:10 -04:00
Do not emit WriteStream's drain event before ws.write has been called.
This commit is contained in:
@@ -840,7 +840,10 @@ WriteStream.prototype.flush = function () {
|
||||
var self = this;
|
||||
|
||||
var args = this._queue.shift();
|
||||
if (!args) return self.emit('drain');
|
||||
if (!args) {
|
||||
if (this.drainable) { self.emit('drain'); }
|
||||
return;
|
||||
}
|
||||
|
||||
this.busy = true;
|
||||
|
||||
@@ -896,6 +899,8 @@ WriteStream.prototype.write = function (data) {
|
||||
throw new Error('stream not writeable');
|
||||
}
|
||||
|
||||
this.drainable = true;
|
||||
|
||||
var cb;
|
||||
if (typeof(arguments[arguments.length-1]) == 'function') {
|
||||
cb = arguments[arguments.length-1];
|
||||
|
||||
@@ -17,3 +17,12 @@ var file = path.join(common.fixturesDir, "write.txt");
|
||||
stream.destroy();
|
||||
})();
|
||||
|
||||
(function() {
|
||||
var stream = fs.createWriteStream(file);
|
||||
|
||||
stream.addListener('drain', function () {
|
||||
assert.fail('"drain" event must not be emitted before stream.write() has been called at least once.')
|
||||
});
|
||||
stream.destroy();
|
||||
})();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user