-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
streams: refactor getHighWaterMark in state.js #20415
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,19 +2,19 @@ | |
|
||
const { ERR_INVALID_OPT_VALUE } = require('internal/errors').codes; | ||
|
||
function highWaterMarkFrom(options, isDuplex, duplexKey) { | ||
return options.highWaterMark != null ? options.highWaterMark : | ||
isDuplex ? options[duplexKey] : null; | ||
} | ||
|
||
function getHighWaterMark(state, options, duplexKey, isDuplex) { | ||
let hwm = options.highWaterMark; | ||
const hwm = highWaterMarkFrom(options, isDuplex, duplexKey); | ||
if (hwm != null) { | ||
if (typeof hwm !== 'number' || !(hwm >= 0)) | ||
throw new ERR_INVALID_OPT_VALUE('highWaterMark', hwm); | ||
return Math.floor(hwm); | ||
} else if (isDuplex) { | ||
hwm = options[duplexKey]; | ||
if (hwm != null) { | ||
if (typeof hwm !== 'number' || !(hwm >= 0)) | ||
throw new ERR_INVALID_OPT_VALUE(duplexKey, hwm); | ||
return Math.floor(hwm); | ||
if (typeof hwm !== 'number' || !(hwm >= 0)) { | ||
const name = isDuplex ? duplexKey : 'highWaterMark'; | ||
throw new ERR_INVALID_OPT_VALUE(`options.${name}`, hwm); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The only reason for making this change was to be consistent with #20284 but I'm happy to remove this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error constructors are different though. This one is more specific since it's not |
||
} | ||
return Math.floor(hwm); | ||
} | ||
|
||
// Default value | ||
|
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.
Could we also change
hwm >= 0
tohwm < 0
? That negation is just confusing, I think.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.
Agreed.
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.
That has a different meaning though because it does not catch
NaN
anymore.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.
Good point. In that case maybe we should be checking for that explicitly? The fact that both me and @lpinca missed it means it is likely to get missed again in the future and then no one might correct it.
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.
Well, hopefully we have tests for it ;-) Besides that, I guess it would be good to add a comment next to it.
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.
It seems we don't as CI is green for this :)It wasn't changed yet, sorry.
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 think we have tests actually. @danbev hasn't made the change yet. Anyway, I'm fine with adding a comment. Just not a big fan of non-obvious checks like this.
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.
Indeed, it would be semver-major but using
Number.isInteger()
seems the ideal solution.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.
Sorry about the delay on this. I'll take a closer look tomorrow (public holiday here today)