-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
lib: remove redundant code from timers.js #3143
Conversation
Seems to have originated along with the start of timers, ala pre- bc47353, perhaps insert was once used in more than one place. Not sure. LGTM. Can you ensure there is something to test that negative timeouts do not fire? |
Can you leave this check and remove the one at the place where it is called? |
@Fishrock123 Regarding testing negative timeouts: Since |
@thefourtheye Yes, that is a slightly better approach. Thanks for suggesting it. I've made the change and pushed. |
LGTM. |
@@ -26,11 +26,11 @@ var lists = {}; | |||
// the main function - creates lists on demand and the watchers associated | |||
// with them. | |||
function insert(item, msecs) { | |||
if (msecs < 0) return; | |||
|
|||
item._idleStart = Timer.now(); | |||
item._idleTimeout = msecs; |
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.
isn't this line also redundant?
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.
Yes. In fact, the whole separation of insert()
from active()
at this point seems redundant. Just pushed an additional commit.
Yes, active is public but should not be -- see: #896 (I'll deal with this soon(tm).) I'd add a test anyways since it currently is public, if the others don't already test it. I haven't looked. |
@Fishrock123 Per your suggestion, I've added a test for |
@Fishrock123 Regarding #896, if (and only if) you want, I'd be happy to take the first step of that off your plate and make those APIs private within the file and replace the existing exposed functions with deprecation warning-wrapped versions and put it in a semver major PR. |
@Trott not worthwhile I think. They should be reworked at the same time. I'll look at it once I'm back from vacation. |
This LGTM if it works & CI is happy. |
legitTimers.forEach(function(legit) { | ||
active(legit); | ||
// active() should mutate these objects | ||
assert.notDeepEqual(Object.keys(legit), ['_idleTimeout']); |
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 not just hasOwnProperty
? Also I feel that if we can check the values also it would be better.
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.
Shouldn't this check _idleStart
also?
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.
Also note that we do now have notDeepStrictEqual
:D
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.
@thefourtheye @Fishrock123 OK, I've improved the tests quite a bit, I think. Looks good to you now?
insert() is only called from one place where there is already a check that msecs is greater than or equal to zero, so do not repeat the check inside insert(). timers.active() is not documented and should not be exposed, but since it is exposed for now, let's test it.
Made the tests a fair bit more rigorous with input from @thefourtheye and @Fishrock123. New CI: https://ci.nodejs.org/job/node-test-pull-request/426/ |
const assert = require('assert'); | ||
const active = require('timers').active; | ||
|
||
// active() should not create a timer for these |
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.
should, or should not?
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.
AH, this should be "should". :)
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.
Fixed the typo. Thanks for the catch.
bogusTimers.forEach(function(bogus) { | ||
const savedTimeout = bogus._idleTimeout; | ||
active(bogus); | ||
// active() should not mutate these objects |
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.
Nit: these?
LGTM |
insert() is only called from one place where there is already a check that msecs is greater than or equal to zero, so do not repeat the check inside insert(). timers.active() is not documented and should not be exposed, but since it is exposed for now, let's test it. PR-URL: nodejs#3143 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Landed in 070aac4 |
insert() is only called from one place where there is already a check that msecs is greater than or equal to zero, so do not repeat the check inside insert(). timers.active() is not documented and should not be exposed, but since it is exposed for now, let's test it. PR-URL: #3143 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
insert() is only called from one place where there is already a check
that msecs is greater than or equal to zero, so do not repeat the check
inside insert().