Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixup: simplify
  • Loading branch information
ronag committed Sep 20, 2019
commit 5da8563bae3eaa3bdced04fac1a2182da878aac2
23 changes: 5 additions & 18 deletions lib/_stream_writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,20 +437,12 @@ function doWrite(stream, state, writev, len, chunk, encoding, cb) {
state.sync = false;
}

function onwriteError(stream, state, sync, er, cb) {
if (sync) {
process.nextTick(onwriteErrorNT, stream, state, er, cb);
} else {
onwriteErrorNT(stream, state, er, cb);
}
}

function onwriteErrorNT(stream, state, er, cb) {
function onwriteError(stream, state, er, cb) {
--state.pendingcb;

cb(er);
// This can emit error, but error must always follow cb.
errorMaybe(stream, er);
errorOrDestroy(stream, er);
}

function onwrite(stream, er) {
Expand All @@ -468,15 +460,10 @@ function onwrite(stream, er) {

if (er) {
state.errored = true;
Copy link
Copy Markdown
Member Author

@ronag ronag Aug 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cannot use errorEmitted since it must be set after cb and cb must be invoked asynchronously. Thus without this we have no way to synchronously tell if a stream has errored.

Copy link
Copy Markdown
Member Author

@ronag ronag Aug 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cannot use destroyed since it will not be set on !autoDestroy.

if (state.autoDestroy) {
stream.destroy(er, (err) => {
// TODO(ronag): Minor optimization opportunities:
// - We might no longer be sync here.
// - Closure allocation can probably be optimized away.
onwriteError(stream, state, sync, err, cb);
});
if (sync) {
process.nextTick(onwriteError, stream, state, er, cb);
} else {
onwriteError(stream, state, sync, er, cb);
onwriteError(stream, state, er, cb);
}
} else {
// Check if we're actually ready to finish, but don't emit yet
Expand Down