-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
doc: add topic - event loop, timers, nextTick()
#4936
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
Changes from 1 commit
46f0702
5a28415
dc1b8a5
bb5b682
ba98380
936bf17
35cf726
f80d7cc
254694b
45fb2fe
d6d76f5
c133caf
f425164
1bd3e6c
7574d4b
8dc6ecb
d82a7f1
1dc26f6
82d0fb8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -164,7 +164,7 @@ time thresholds have been reached_. If one or more timers are ready, the | |
| event loop will wrap back to the timers phase to execute those timers' | ||
| callbacks. | ||
|
|
||
| ### `setImmediate()`: | ||
| ### `setImmediate`: | ||
|
|
||
| `setImmediate()` is actually a special timer that runs in a separate phase of | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. its a timer? really? that surprises me, its behaviour seems unrelated to time.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TBH, I do not have enough intimate knowledge of the codebase to argue for or against whether or not it is a timer. I just said its a special form of timer because that's what I got from the presentation which was the basis. I'm hoping to get this landed ASAP, so that EVERYONE can discuss and refine this doc
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| the event loop. It uses a libuv API that schedules callbacks to execute after | ||
|
|
@@ -281,7 +281,7 @@ To get around this the `'listening'` event is queued in a `nextTick()` to allow | |
| the script to run to completion. Which allows the user to set any event | ||
| handlers they want. | ||
|
|
||
| ## process.nextTick() vs `setImmediate()` | ||
| ## `process.nextTick()` vs `setImmediate()` | ||
|
|
||
| We have two calls that are similar as far as users are concerned, but their | ||
| names are confusing. | ||
|
|
@@ -322,7 +322,7 @@ server.on('listening', function() { }); | |
| ``` | ||
|
|
||
| Say that listen() is run at the beginning of the event loop, but the | ||
| listening callback is placed in a setImmediate. Now, unless a hostname | ||
| listening callback is placed in a `setImmediate()`. Now, unless a hostname | ||
| is passed binding to the port will happen immediately. Now for the | ||
| event loop to proceed it must hit the `poll` phase, which means there | ||
| is a non-zero chance that a connection could have been received allowing | ||
|
|
||
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'm not sure that I would call it a timer really since it has no "timeout" value per se ...
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 just used @trevnorris' words from the presentation link in the OP, but I am open so suggestions as per his approval.
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's located in https://nodejs.org/api/timers.html :)