Do not emit WriteStream's drain event before ws.write has been called.
This commit is contained in:
parent
f5e4047064
commit
ccf4afa256
@ -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();
|
||||
})();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user