Skip to content

Commit

Permalink
stream: removed unecessary writing property
Browse files Browse the repository at this point in the history
writecb casted to boolean has the same
value as writing.
  • Loading branch information
ronag committed Apr 17, 2020
1 parent d3d5eca commit 38d9b7f
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions lib/_stream_writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,6 @@ function WritableState(options, stream, isDuplex) {
// socket or file.
this.length = 0;

// A flag to see when we're in the middle of a write.
this.writing = false;

// When true all writes will be buffered until .uncork() call
this.corked = 0;

Expand Down Expand Up @@ -188,6 +185,14 @@ function WritableState(options, stream, isDuplex) {
this.corkedRequestsFree = corkReq;
}

ObjectDefineProperties(WritableState.prototype, {
writing: {
get() {
return !!this.writecb;
}
}
});

WritableState.prototype.getBuffer = function getBuffer() {
let current = this.bufferedRequest;
const out = [];
Expand Down Expand Up @@ -318,7 +323,7 @@ Writable.prototype.uncork = function() {
if (state.corked) {
state.corked--;

if (!state.writing &&
if (!state.writecb &&
!state.corked &&
!state.bufferProcessing &&
state.bufferedRequest)
Expand Down Expand Up @@ -349,7 +354,7 @@ function writeOrBuffer(stream, state, chunk, encoding, cb) {
if (!ret)
state.needDrain = true;

if (state.writing || state.corked || state.errored) {
if (state.writecb || state.corked || state.errored) {
const last = state.lastBufferedRequest;
state.lastBufferedRequest = {
chunk,
Expand All @@ -375,7 +380,6 @@ function writeOrBuffer(stream, state, chunk, encoding, cb) {
function doWrite(stream, state, writev, len, chunk, encoding, cb) {
state.writelen = len;
state.writecb = cb;
state.writing = true;
state.sync = true;
if (state.destroyed)
state.onwrite(new ERR_STREAM_DESTROYED('write'));
Expand Down Expand Up @@ -409,7 +413,6 @@ function onwrite(stream, er) {
return;
}

state.writing = false;
state.writecb = null;
state.length -= state.writelen;
state.writelen = 0;
Expand Down Expand Up @@ -484,7 +487,7 @@ function afterWrite(stream, state, count, cb) {

// If there's something in the buffer waiting, then invoke callbacks.
function errorBuffer(state, err) {
if (state.writing || !state.bufferedRequest) {
if (state.writecb || !state.bufferedRequest) {
return;
}

Expand Down Expand Up @@ -551,7 +554,7 @@ function clearBuffer(stream, state) {
// it means that we need to wait until it does.
// also, that means that the chunk and cb are currently
// being processed, so move the buffer counter past them.
if (state.writing) {
if (state.writecb) {
break;
}
}
Expand Down Expand Up @@ -621,7 +624,7 @@ function needFinish(state) {
!state.errored &&
state.bufferedRequest === null &&
!state.finished &&
!state.writing);
!state.writecb);
}

function callFinal(stream, state) {
Expand Down

0 comments on commit 38d9b7f

Please sign in to comment.