From 58568232234da60931817ccc98da2bf14d121177 Mon Sep 17 00:00:00 2001 From: isaacs Date: Mon, 12 Nov 2012 23:28:56 -0800 Subject: [PATCH] streams2: Fix duplex no-half-open logic --- lib/_stream_duplex.js | 27 +++------------------------ 1 file changed, 3 insertions(+), 24 deletions(-) diff --git a/lib/_stream_duplex.js b/lib/_stream_duplex.js index 30b4692..ef74c34 100644 --- a/lib/_stream_duplex.js +++ b/lib/_stream_duplex.js @@ -47,38 +47,17 @@ function Duplex(options) { if (options && options.allowHalfOpen === false) this.allowHalfOpen = false; - this.once('finish', onfinish); this.once('end', onend); } -// the no-half-open enforcers. -function onfinish() { - // if we allow half-open state, or if the readable side ended, - // then we're ok. - if (this.allowHalfOpen || this._readableState.ended) - return; - - // mark that we're done. - this._readableState.ended = true; - - // tell the user - if (this._readableState.length === 0) - this.emit('end'); - else - this.emit('readable'); -} - +// the no-half-open enforcer function onend() { // if we allow half-open state, or if the writable side ended, // then we're ok. if (this.allowHalfOpen || this._writableState.ended) return; - // just in case the user is about to call write() again. - this.write = function() { - return false; - }; - // no more data can be written. - this.end(); + // But allow more writes to happen in this tick. + process.nextTick(this.end.bind(this)); } -- 2.7.4