stream: inline and simplify onwritedrain

Inline and simplify onwritedrain. Also remove comment that seems to be
outdated/invalid.

PR-URL: https://github.com/nodejs/node/pull/29037
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
Robert Nagy 2019-08-07 21:25:45 +02:00 committed by Rich Trott
parent a0e2c6d284
commit 83495e7783

View File

@ -478,21 +478,13 @@ function onwrite(stream, er) {
} }
function afterWrite(stream, state, finished, cb) { function afterWrite(stream, state, finished, cb) {
if (!finished) if (!finished && state.length === 0 && state.needDrain) {
onwriteDrain(stream, state);
state.pendingcb--;
cb();
finishMaybe(stream, state);
}
// Must force callback to be called on nextTick, so that we don't
// emit 'drain' before the write() consumer gets the 'false' return
// value, and has a chance to attach a 'drain' listener.
function onwriteDrain(stream, state) {
if (state.length === 0 && state.needDrain) {
state.needDrain = false; state.needDrain = false;
stream.emit('drain'); stream.emit('drain');
} }
state.pendingcb--;
cb();
finishMaybe(stream, state);
} }
// If there's something in the buffer waiting, then process it // If there's something in the buffer waiting, then process it