Skip to content

Commit 79f847d

Browse files
authored
Update event loop.md
1 parent 14d15dd commit 79f847d

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

JavaScript/event loop.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,17 +155,19 @@ fs.readFile(".prettierc.json", () => {
155155
```
156156
**process.nextTick()**
157157

158-
process.nextTick() will be processed after the current operation is completed, regardless of current phase of the event loop.
159-
Operation is defined as a transition from the underlying C/C++ handler, and handling the JavaScript that needs to be executed.
160-
161-
* process.nextTick() fires immediately on the same phase
162-
* setImmediate() fires on the following iteration or 'tick' of the event loop
158+
* process.nextTick() will be processed after the current operation is completed, regardless of current phase of the event loop.
159+
* Operation is defined as a transition from the underlying C/C++ handler, and handling the JavaScript that needs to be executed.
160+
* It schedules a callback function to be executed immediately after the current operation completes, but before the event loop proceeds to the next phase.
163161

164162
**Why use process.nextTick()?**
165163

166164
* Allow users to handle errors, cleanup unneeded resources, or try the request again before the event loop continues.
167165
* At times to allow a callback to run after the call stack has unwound but before the event loop continues.
168166

167+
**process.nextTick() vs setImmediate()**
168+
* process.nextTick() fires immediately on the same phase
169+
* setImmediate() fires on the following iteration or 'tick' of the event loop
170+
169171
```javascript
170172
setImmediate(() => {
171173
console.log("immediate")

0 commit comments

Comments
 (0)