Browse Source

streams2: Writable only emit 'finish' once

v0.9.4-release
isaacs 12 years ago
parent
commit
5760244cc6
  1. 5
      lib/_stream_writable.js

5
lib/_stream_writable.js

@ -190,7 +190,8 @@ function onwrite(stream, er) {
cb();
}
if (state.length === 0 && (state.ended || state.ending)) {
if (state.length === 0 && (state.ended || state.ending) &&
!state.finished && !state.finishing) {
// emit 'finish' at the very end.
state.finishing = true;
stream.emit('finish');
@ -245,7 +246,7 @@ Writable.prototype.end = function(chunk, encoding) {
state.ending = true;
if (chunk)
this.write(chunk, encoding);
else if (state.length === 0) {
else if (state.length === 0 && !state.finishing && !state.finished) {
state.finishing = true;
this.emit('finish');
state.finished = true;

Loading…
Cancel
Save