-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
doc: add active, enroll and unenroll #11736
Conversation
doc/api/timers.md
Outdated
Example: | ||
|
||
```js | ||
var timers = require('timers') |
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.
This and other lines are missing semicolons.
doc/api/timers.md
Outdated
```js | ||
var timers = require('timers') | ||
var atimer = { | ||
_onTimeout: function () { |
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.
minor nit: should be function() {
I'm not sure if these methods are actually intended to be public or not, even though they are not underscore-prefixed? /cc @Fishrock123 |
This commit adds documentation for the public `timers` methods `active`, `enroll` and `unenroll`.
At this point (a) they're public and (b) being used, we may as well document them. |
I very much don't think we should document them as for public use.
It may be worthwhile to mention more specifics of the timers implementation that relate to these, such as that If we want to mention actually useful stuff, then we should probably mention just |
I couldn't think of much for an introduction. So I copied the point made about As for the API being confusing, it was more confusing when I learned about it via its usage in https://github.com/davidmarkclements/fast-date/blob/master/fallback.js and there wasn't any documentation on it. |
uuuugh ok. Let's document it but tell people to not use it / avoid it. |
@Fishrock123 how would you revise the introduction? |
Aside: I've been stewing over whether we need an official |
@jasnell would the classification you're looking for be "volatile"? |
No, because the APIs in question might not change frequently or at all. They may ... the defining characteristic would be that they simply are not recommended (for whatever reason) |
In a way, I think it's similar to |
@jasnell Maybe make those APIs non-enumerable so they don't show up in auto-completion would be a start.. |
@nodejs/ctc @Fishrock123 ... would appreciate more input on this |
They were never intended for public use, just an implementation detail that leaked out due to lack of foresight. If the argument for documenting them is to avoid confusion for people stumbling upon them, it should be a one-liner like "Implementation detail. Do not use." |
Personally I'd prefer a warning about cleaning up state than warning not to use - especially because I've now used it in a published module as a performance enhancement. |
How about this intro:
|
In general, please avoid the use of directed pronouns like
|
I definitely agree with @bnoordhuis' sentiment that the added documentation should include a strong warning against using these methods. It should likely also be noted that the specific implementation details of these particular methods could change and that while the API is publicly accessible, ongoing support is not guaranteed. (That said, we would definitely have to take any changes to these through a proper deprecation cycle in practice) |
@jasnell so do you have any other changes for the proposed introduction rewording? |
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.
In general this definitely needs the warning text and a clear description of the state management requirements.
doc/api/timers.md
Outdated
## Manual Timers | ||
|
||
It is possible to make any object a timer. Reusing an existing object as a timer | ||
slightly reduces memory consumption. Another advantage is that you control |
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.
Again, please avoid the use of you
in the documentation text :-)
doc/api/timers.md
Outdated
|
||
```js | ||
var timers = require('timers'); | ||
var atimer = { |
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.
s/var/const
doc/api/timers.md
Outdated
@@ -162,6 +162,50 @@ added: v0.0.1 | |||
|
|||
Cancels a `Timeout` object created by [`setTimeout()`][]. | |||
|
|||
## Manual Timers | |||
|
|||
It is possible to make any object a timer. Reusing an existing object as a timer |
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 would say something like, It is possible, but not recommended, to make any object into a timer.
I'm still -1 on anything beyond a "do not use." The language proposed in #11736 (comment) is still an encouragement to use them. It's easy enough to make a queue or linked list that hangs off a setTimeout() timer, you don't need enroll/unenroll for that. |
@bnoordhuis ... if the APIs really should not be used then we should move the implementation to |
I agree. I understand that it may have been a mistake, but they are written with the convention implying they are a public API. My opinion is that any such API should be documented since people will find it, and they will use it under the assumption that it is public. |
Then a note in the documentation explaining they shouldn't be used should suffice. I'm not out to break existing code but new code should be steered away from using them. |
doc/api/timers.md
Outdated
Example: | ||
|
||
```js | ||
var timers = require('timers'); |
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.
Please encourage Strict mode.
doc/api/timers.md
Outdated
_onTimeout: function() { | ||
console.log('timeout'); | ||
} | ||
} |
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.
Our coding standard expects a semi-colon at the end.
I agree with @bnoordhuis, given that we don't want people to use them, lets just say that and then start the deprecation process. |
doc/api/timers.md
Outdated
circumstances this can be advantageous. However, in general practice, using | ||
this API is strongly discouraged. This is due to the fact that when using this API | ||
it is important to track timer enrollment state. A memory leak will occur if a | ||
timer is enrolled but never unenrolled. |
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.
This paragraph can be simplified a bit...
It is possible (but not recommended) to make any object a timer. In general
practice, however, using this API is **strongly discouraged** due to the potential
for memory leaks should such timers fail to be properly unenrolled.
|
||
timers.enroll(atimer, 1000); // make the `atimer` object a timer | ||
timers.active(atimer); // start the timer | ||
``` |
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.
This should include a clear example showing the timer being unenroll()
'd per the warning above
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 does show it. Line 183, in the callback from the timer completion.
There was no progress here since a while and I fear this might not get merged as there were quite a few concerns about publishing this at all (and I share these concerns). |
Closing this is ok. I do think something should be done here but this pr apparently isn't it. |
This PR adds documentation for the public
timers
methodsactive
,enroll
andunenroll
.Checklist
Affected core subsystem(s)
doc