-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
[DEP0096] DeprecationWarning: timers.unenroll() question #20261
Comments
/cc @Fishrock123 |
It will work, yes, but you should probably move to using Also,
In the future I want to expose this internal function which does that in a better way but I wasn't sure what the end API should be: https://github.com/nodejs/node/blob/master/lib/internal/timers.js#L85-L96 I could do that sooner I suppose, as the API seems fine to me. I guess browsers might also be interested in this so maybe in the distant future |
Maybe the deprecation should also mention that if you are using |
Maybe. I'm fine with moving, just not sure how to make the move. This came out from the "mysql" module. Is there like a guide I can read to understand the changes I need to make? |
I'm just basically enrolling an object to a timer and I extend the timeout every time a data chunk arrives so it is basically an inactivity timeout. |
This older code: class ThingWithTimer {
constructor () {
Timers.enroll(this)
}
start () {
Timers.active(this)
}
refresh () {
Timers.active(this)
}
done () {
Timers.unenroll(this)
}
} Becomes something like: class ThingWithTimer {
constructor () {
this.timer = null
}
start () {
this.timer = setTimeout()
}
refresh () {
// Refresh timeout in-place
Timers.active(this.timer) // Eventually, this.timer.refresh() or refreshTimeout(this.timer)
}
done () {
clearTimeout(this.timer)
}
} |
Awesome, will try it out. Is there a way to feature detect when to use this new method vs the old method? |
Also I saw in the code there is Timeout.prototype[refreshFnSymbol] already. Any reason not to bring it out from behind a symbol in like 10.1? Seems odd to mix the two APIs temporarily. It would also be an easy way to feature detect from my question above: see if there is a refresh method for timers, right? |
Always. I think you need to be on like Node 0.8 for the full API to be realistically worse for perf. The APIs in the example exist and function correctly on all versions of Node.
From the above, I wasn't sure if something like Such an approach could also work better with #19683. (Although something like a Ehhh, I'll open a PR to make it public. :) |
Ok, PR up at #20298 |
Originally added in bb5575a discussions such as nodejs#20261 show the usefulness of this API to the Node.js ecosystem. PR-URL: nodejs#20298
Originally added in bb5575a discussions such as #20261 show the usefulness of this API to the Node.js ecosystem. PR-URL: #20298 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ujjwal Sharma <usharma1998@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Originally added in bb5575a discussions such as #20261 show the usefulness of this API to the Node.js ecosystem. PR-URL: #20298 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ujjwal Sharma <usharma1998@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
#20298 landed and was released in 11.0.0. @dougwilson Can this issue be closed? Or is there more to be done here? |
Yes, all resolved, thank you. |
Just update the mysql library to latest version
|
I have a question on this deprecation. I am using Timers.active to start a passive timer on a socket and Timers.unenroll to stop it. I see it says I need to change unenroll to clearTimeout but nothing about Timers.active. Will clearTimeout unenroll the timer created from Timers.active ?
The text was updated successfully, but these errors were encountered: