New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: make stdout flush on newer versions of Node.js #501
Conversation
if (process.stdout._handle && typeof process.stdout._handle.setBlocking === 'function') { | ||
process.stdout._handle.setBlocking(true) | ||
process.stderr._handle.setBlocking(true) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Solution seems fine to me.
One note: If _handle
exists it's always a net.Socket
(or inherits from it), and thus setBlocking()
will always exist.
(This has not been changed in years.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I'm curious, does this actually work when done retroactively?
If you have async writes and they you do this does it immediately cause a blocking flush on call? If you don't know, that's fine, I'll investigate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Fishrock123 trying to go make sure yargs supports all the way back to 0.8
currently:
Benjamins-MBP:yargs benjamincoe$ node --version
v0.8.28
Benjamins-MBP:yargs benjamincoe$ node
> process.stdout._handle.setBlocking
undefined
was hoping it would work retroactively, and tried this initially, it does not appear to. You need to have set blocking to true before you begin writing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like it was added in v0.11.2: nodejs/node@20176a9 in response to nodejs/node-v0.x-archive#3584
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose this doesn't ever manifest as an issue before 0.11.2 then, but I haven't tested it.
see #497