-
Notifications
You must be signed in to change notification settings - Fork 30k
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
timers: give Timeouts a constructor name #5793
Conversation
LGTM |
2 similar comments
LGTM |
LGTM |
should be safe for v4, no? |
@@ -439,7 +439,7 @@ exports.clearInterval = function(timer) { | |||
}; | |||
|
|||
|
|||
const Timeout = function(after) { | |||
function Timeout(after) { |
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.
Any reason not to make it a class Timeout
?
class Timeout {
constructor(after) {
this._called = false;
this._idleTimeout = after;
this._idlePrev = this;
this._idleNext = this;
this._idleStart = null;
this._onTimeout = null;
this._repeat = null;
}
unref () {
if (this._handle) {
this._handle.unref();
} else if (typeof this._onTimeout === 'function') {
var now = TimerWrap.now();
if (!this._idleStart) this._idleStart = now;
var delay = this._idleStart + this._idleTimeout - now;
if (delay < 0) delay = 0;
// Prevent running cb again when unref() is called during the same cb
if (this._called && !this._repeat) {
exports.unenroll(this);
return;
}
var handle = reuse(this);
this._handle = handle || new TimerWrap();
this._handle.owner = this;
this._handle[kOnTimeout] = function unrefdHandle() {
this.owner._onTimeout();
if (!this.owner._repeat)
this.owner.close();
};
this._handle.start(delay, 0);
this._handle.domain = this.domain;
this._handle.unref();
}
return this;
}
ref() {
if (this._handle)
this._handle.ref();
return this;
}
close() {
this._onTimeout = null;
if (this._handle) {
this._handle[kOnTimeout] = null;
this._handle.close();
} else {
exports.unenroll(this);
}
return 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.
No gain, more code change.
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, it modernizes things a little and makes them more explicit. If we want to minimize change why not keep it const Timeout
and do const Timeout = function Timeout
- by naming the function expression you get the same trace.
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.
Why even assign it though? It's unnecessary.
Typically we have avoided modernization unless it meant performance increases or was part of some refactor that touched the code a lot anyways.
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.
Fair enough - I'm sorry if all these questions annoy you :)
LGTM |
Refs: nodejs#5792 PR-URL: nodejs#5793 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Сковорода Никита Андреевич <[email protected]>
Fixes: nodejs#5823 Refs: nodejs#5793 PR-URL: nodejs#5825 Reviewed-By: Myles Borins <[email protected]>
Refs: #5792 PR-URL: #5793 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Сковорода Никита Андреевич <[email protected]> Conflicts: test/message/timeout_throw.out
Fixes: #5823 Refs: #5793 PR-URL: #5825 Reviewed-By: Myles Borins <[email protected]>
Notable changes: * buffer: Now properly throws RangeErrors on out-of-bounds writes (Matt Loring) #5605 - This effects write{Float|Double} when the noAssert option is not used. * timers: - Returned timeout objects now have a Timeout constructor name (Jeremiah Senkpiel) #5793 - Performance of Immediate processing is now ~20-40% faster (Brian White) #4169 * vm: Fixed a contextify regression introduced in v5.9.0 (Ali Ijaz Sheikh) #5800 PR-URL: #5831
Notable changes: * buffer: Now properly throws RangeErrors on out-of-bounds writes (Matt Loring) #5605 - This effects write{Float|Double} when the noAssert option is not used. * timers: - Returned timeout objects now have a Timeout constructor name (Jeremiah Senkpiel) #5793 - Performance of Immediate processing is now ~20-40% faster (Brian White) #4169 * vm: Fixed a contextify regression introduced in v5.9.0 (Ali Ijaz Sheikh) #5800 PR-URL: #5831
Notable changes: * buffer: Now properly throws RangeErrors on out-of-bounds writes (Matt Loring) #5605 - This effects write{Float|Double} when the noAssert option is not used. * timers: - Returned timeout objects now have a Timeout constructor name (Jeremiah Senkpiel) #5793 - Performance of Immediate processing is now ~20-40% faster (Brian White) #4169 * vm: Fixed a contextify regression introduced in v5.9.0 (Ali Ijaz Sheikh) #5800 PR-URL: #5831
Notable changes: * buffer: Now properly throws RangeErrors on out-of-bounds writes (Matt Loring) nodejs#5605 - This effects write{Float|Double} when the noAssert option is not used. * timers: - Returned timeout objects now have a Timeout constructor name (Jeremiah Senkpiel) nodejs#5793 - Performance of Immediate processing is now ~20-40% faster (Brian White) nodejs#4169 * vm: Fixed a contextify regression introduced in v5.9.0 (Ali Ijaz Sheikh) nodejs#5800 PR-URL: nodejs#5831
@Fishrock123 can you confirm that this is safe and ready for v4? |
if this does land we should apply the lint fixes found in #5825 |
@thealphanerd should be safe. It's a sorta-feature, but will only show up in logs I think. It's not even exported, so you can't do instanceof checks with it. |
@Fishrock123 I'm going to defer to your judgement here. Please feel free to send a backport PR or change the label |
Pull Request check-list
make -j8 test
(UNIX) orvcbuild test nosign
(Windows) pass withthis change (including linting)?
Affected core subsystem(s)
timers
Description of change
Refs: #5792
No functional difference, this is for clarity only.