GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — stream: pipeline don't destroy Duplex src before 'finish' by ronag · Pull Request #32966 · nodejs/node Conversation
|
| const wState = stream._writableState; | ||
|
|
||
| const writableEnded = stream.writableEnded || | ||
| (wState && wState.ended); | ||
| const writableFinished = stream.writableFinished || | ||
| (wState && wState.finished); | ||
|
|
||
| const willFinish = stream.writable || | ||
| (writableEnded && !writableFinished); | ||
| const willEnd = stream.readable; | ||
|
|
||
| if (err || !final || !stream.readable) { | ||
| destroyImpl.destroyer(stream, err); | ||
| if (!err) { | ||
| // First | ||
| if (reading && !writing && willFinish) { | ||
| return callback(); | ||
| } | ||
|
|
||
| // Last | ||
| if (!reading && writing && willEnd) { | ||
| return callback(); | ||
| } |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Nit: it is possible to reduce the code branches a bit:
| const wState = stream._writableState; | |
| const writableEnded = stream.writableEnded || | |
| (wState && wState.ended); | |
| const writableFinished = stream.writableFinished || | |
| (wState && wState.finished); | |
| const willFinish = stream.writable || | |
| (writableEnded && !writableFinished); | |
| const willEnd = stream.readable; | |
| if (err || !final || !stream.readable) { | |
| destroyImpl.destroyer(stream, err); | |
| if (!err) { | |
| // First | |
| if (reading && !writing && willFinish) { | |
| return callback(); | |
| } | |
| // Last | |
| if (!reading && writing && willEnd) { | |
| return callback(); | |
| } | |
| if (!err) { | |
| // Check if the last stream will end: | |
| if (!reading) { | |
| if (writing && stream.readable) { | |
| return callback(); | |
| } | |
| // First stream | |
| } else if (!writing) { | |
| if (stream.writable) { | |
| return callback(); | |
| } | |
| const wState = stream._writableState; | |
| const writableEnded = stream.writableEnded || | |
| (wState && wState.ended); | |
| const writableFinished = stream.writableFinished || | |
| (wState && wState.finished); | |
| if (writableEnded && !writableFinished) | |
| return callback(); | |
| } | |
| } |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
@BridgeAR: Any specific reason? This does make it a bit harder to read in my opinon.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Code should IMO always only run when necessary. Right now some code is executed that is only needed in some situations.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This is not a hot path so readability should IMO come first. I think I can make a compromise 😄. PTAL.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| destroyImpl.destroyer(stream, err); | ||
| if (!err) { | ||
| // First | ||
| if (reading && !writing && willFinish) { |
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The willFinish part here is the significant change. Before we only checked stream.writable.
The rest of the changes should be logically the same.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
blocked pending #32954 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
closed in favor of #32968 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
Duplex stream pipeline regression in 13
There was an error while loading. Please reload this page.