Do not emit WriteStream's drain event before ws.write has been called.

This commit is contained in:
Tobie Langel 2010-09-08 14:28:31 +02:00 committed by Ryan Dahl
parent f5e4047064
commit ccf4afa256
2 changed files with 15 additions and 1 deletions

View File

@ -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];

View File

@ -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();
})();