Skip to content
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

Closed
wants to merge 18 commits into from
Closed

Doc: Adding guide on Timers #6825

wants to merge 18 commits into from

Conversation

ryanmurakami
Copy link
Contributor

Checklist
  • the commit message follows commit guidelines
Affected core subsystem(s)

doc

Description of change

Adding guide of using Timers in Node per nodejs/docs#76.

@nodejs-github-bot nodejs-github-bot added the doc Issues and PRs related to the documentations. label May 18, 2016
@Fishrock123 Fishrock123 self-assigned this May 18, 2016
setTimeout(myFunc, 1500);
```

The above function ```myFunc()``` will execute after approximately 1500 milliseconds (or 1.5 seconds) due to the call of ```setTimeout()```.
Copy link
Member

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

@mscdex mscdex added the timers Issues and PRs related to the timers subsystem / setImmediate, setInterval, setTimeout. label May 18, 2016
@jasnell
Copy link
Member

jasnell commented May 18, 2016

@nodejs/documentation

@ryanmurakami
Copy link
Contributor Author

@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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be ```js

@Fishrock123
Copy link
Member

I think we'd probably better with clearer heading names. I'll try to give this more review later this week.

@thefourtheye
Copy link
Contributor

I see a lot of long lines. Can you wrap them at 80 chars please?

@ryanmurakami
Copy link
Contributor Author

@thefourtheye done, thanks!
@Fishrock123 I'll rework them a bit. I'd like to keep the "personality" but can add a little more specific info for each. Thanks for the feedback.

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
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@thefourtheye
Copy link
Contributor

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
Copy link
Member

@jasnell jasnell May 18, 2016

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 ;-) )

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ty

@ryanmurakami
Copy link
Contributor Author

@Fishrock123 Cool! So, I looked at revising that sentence, but I think the way process.nextTick() is executed is already well explained in the guide I link to, so I just placed a direct link to that section. I agree it was getting too confusing and trying to explain what's happening would've taken too much.

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
Copy link
Member

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()`.

Copy link
Contributor Author

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
Copy link
Contributor

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

@thefourtheye
Copy link
Contributor

LGTM - comments

@ryanmurakami
Copy link
Contributor Author

@thefourtheye Thanks for your comments! Good catches! I've updated them and added a note on the differences with window.setTimeout().

### "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()`
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. Added.

Fishrock123 pushed a commit that referenced this pull request Jul 1, 2016
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>
@Fishrock123
Copy link
Member

Looks like there are some whitespace errors, could you please set git config --global --add core.whitespace fix for next time?

Thanks though, squashed and landed in 1299c27 with some nits!

@Fishrock123
Copy link
Member

(Also, since I think this was your first PR to core, welcome! Hopefully the journey to get this in wasn't too much haha.)

@ryanmurakami
Copy link
Contributor Author

@Fishrock123 Yay! Thanks for the welcome! Thanks for all your help, I really learned a ton. Looking forward to future contributions!

@Knighton910
Copy link

Awesome work :)

Fishrock123 pushed a commit that referenced this pull request Jul 5, 2016
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>
@Fishrock123 Fishrock123 mentioned this pull request Jul 5, 2016
@MylesBorins
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Issues and PRs related to the documentations. timers Issues and PRs related to the timers subsystem / setImmediate, setInterval, setTimeout.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants