-
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: Adding guide on Timers #6825
Conversation
setTimeout(myFunc, 1500); | ||
``` | ||
|
||
The above function ```myFunc()``` will execute after approximately 1500 milliseconds (or 1.5 seconds) due to the call of ```setTimeout()```. |
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.
Inline code blocks should be surrounded single backticks
@nodejs/documentation |
@Fishrock123 Thanks for the feedback! I've fixed it. |
|
||
`setImmediate()` allows you to execute code at the beginning of the next event loop cycle. This code will execute *before* any timers or IO operations. I like to think of this code execution as happening "right after this", meaning any code following the `setImmediate()` function call will execute before the `setImmediate()` function argument. Here's an example: | ||
|
||
```javascript |
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.
can be ```js
I think we'd probably better with clearer heading names. I'll try to give this more review later this week. |
I see a lot of long lines. Can you wrap them at 80 chars please? |
@thefourtheye done, thanks! |
The timeout interval that is set cannot be relied upon to execute after | ||
that *exact* number of milliseconds. This is because executing code that | ||
blocks or holds onto the event loop will push the execution of your timeout | ||
back. You *can* guarantee that your timeout will not execute *sooner* than |
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.
timeout function will not execute?
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.
meaning, it won't execute sooner than the timeout, it will execute on or after the timeout.
I liked what I read. Thanks :-) |
|
||
Timers are a collection of global functions in node.js that allow you to | ||
execute code after a set period of time. To fully understand when timer | ||
functions will be executed, it's a good idea to read up on the the node |
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/node/Node.js (here and everywhere else it's mentioned ;-) )
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.
ty
@Fishrock123 Cool! So, I looked at revising that sentence, but I think the way Also, removed deja vu. Good point about it possibly being unfamiliar to readers. Thanks again for the feedback! |
@@ -94,11 +94,11 @@ some major ways they differ. The first is that `process.nextTick()` will run | |||
*before* any `Immediate`s that are set as well as before any scheduled I/O. | |||
The second is that `process.nextTick()` is non-clearable, meaning once | |||
code has been scheduled to execute with `process.nextTick()`, the execution |
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.
Perhaps...
Refer to [this guide][../topics/the-event-loop-timers-and-nexttick#processnexttick]
to better understand the operation of `process.nextTick()`.
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.
sure, sounds good.
|
||
## Controlling the Time Continuum with Node.js | ||
|
||
The Node.js API provides several ways to of scheduling code to execute at |
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.
ways to schedule/ways of scheduling
LGTM - comments |
@thefourtheye Thanks for your comments! Good catches! I've updated them and added a note on the differences with |
### "When I say so" Execution ~ *`setTimeout()`* | ||
|
||
`setTimeout()` can be used to schedule code execution after a designated | ||
amount of milliseconds. This function is similar to `window.setTimeout()` |
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.
Link window.setTimeout()
to https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/setTimeout?
If you don't, I'll do it upon landing.
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.
Got it. Added.
Refs: nodejs/docs#76 PR-URL: #6825 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Looks like there are some whitespace errors, could you please set Thanks though, squashed and landed in 1299c27 with some nits! |
(Also, since I think this was your first PR to core, welcome! Hopefully the journey to get this in wasn't too much haha.) |
@Fishrock123 Yay! Thanks for the welcome! Thanks for all your help, I really learned a ton. Looking forward to future contributions! |
Awesome work :) |
Refs: nodejs/docs#76 PR-URL: #6825 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
I've added the dont-land label for v4.x assuming that this is built on a more modern version of the timers api. Please let me know if this assumption is incorrect |
Checklist
Affected core subsystem(s)
doc
Description of change
Adding guide of using Timers in Node per nodejs/docs#76.