diff options
author | Tobie Langel <tobie.langel@gmail.com> | 2010-09-08 14:28:31 +0200 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2010-09-08 11:58:54 -0700 |
commit | ccf4afa256fc26838a1386b364f415776a47ef4e (patch) | |
tree | 386c48953b4e4b36929f50d76f770f7b2f0f45db | |
parent | f5e40470643d8cc97ad4aa85fbca4b2805cc0481 (diff) | |
download | node-new-ccf4afa256fc26838a1386b364f415776a47ef4e.tar.gz |
Do not emit WriteStream's drain event before ws.write has been called.
-rw-r--r-- | lib/fs.js | 7 | ||||
-rw-r--r-- | test/simple/test-fs-write-stream.js | 9 |
2 files changed, 15 insertions, 1 deletions
@@ -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]; diff --git a/test/simple/test-fs-write-stream.js b/test/simple/test-fs-write-stream.js index 541d819229..6679536f50 100644 --- a/test/simple/test-fs-write-stream.js +++ b/test/simple/test-fs-write-stream.js @@ -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(); +})(); + |