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

This commit is contained in:
Tobie Langel authored and Ryan Dahl committed 2010-09-08 17:56:12 -07:00
1 parent 0b9dab650e
commit 5bbebf3593
2 files changed
+15 -1

No files matched your search

+6 -1
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];
+9
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();
})();