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));
}