From e5a3b873ae2196ad46a50e9ea662bb91eedd484c Mon Sep 17 00:00:00 2001 From: kekekuli Date: Thu, 24 Apr 2025 17:39:56 +0800 Subject: [PATCH 1/7] fix: improve 'Understanding process.nextTick()' page example code. --- .../understanding-processnexttick.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/apps/site/pages/en/learn/asynchronous-work/understanding-processnexttick.md b/apps/site/pages/en/learn/asynchronous-work/understanding-processnexttick.md index d37983c022ad4..fe847c05acb54 100644 --- a/apps/site/pages/en/learn/asynchronous-work/understanding-processnexttick.md +++ b/apps/site/pages/en/learn/asynchronous-work/understanding-processnexttick.md @@ -31,11 +31,11 @@ Use `nextTick()` when you want to make sure that in the next event loop iteratio console.log('Hello => number 1'); setImmediate(() => { - console.log('Running before the timeout => number 3'); + console.log('Running at order 3 or 4, setImmediate'); }); setTimeout(() => { - console.log('The timeout running last => number 4'); + console.log('Running at order 3 or 4, setTimeout'); }, 0); process.nextTick(() => { @@ -43,13 +43,13 @@ process.nextTick(() => { }); ``` -#### Example output: +#### Example output(possible): ```bash Hello => number 1 Running at next tick => number 2 -Running before the timeout => number 3 -The timeout running last => number 4 +Running at order 3 or 4, setImmediate +Running at order 3 or 4, setTimeout ``` -The exact output may differ from run to run. +The exact output may differ from run to run. [setImmediate vs setTimeout](https://nodejs.org/en/learn/asynchronous-work/event-loop-timers-and-nexttick#setimmediate-vs-settimeout) explain the reason. From 8d9abaf84ea5ae8779f3e276ee2fdd4a216d08fb Mon Sep 17 00:00:00 2001 From: kekekuli Date: Thu, 24 Apr 2025 22:54:48 +0800 Subject: [PATCH 2/7] feat: add summary for understanding processnexttick doc --- .../learn/asynchronous-work/understanding-processnexttick.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/site/pages/en/learn/asynchronous-work/understanding-processnexttick.md b/apps/site/pages/en/learn/asynchronous-work/understanding-processnexttick.md index fe847c05acb54..5e335de3aade3 100644 --- a/apps/site/pages/en/learn/asynchronous-work/understanding-processnexttick.md +++ b/apps/site/pages/en/learn/asynchronous-work/understanding-processnexttick.md @@ -52,4 +52,6 @@ Running at order 3 or 4, setImmediate Running at order 3 or 4, setTimeout ``` -The exact output may differ from run to run. [setImmediate vs setTimeout](https://nodejs.org/en/learn/asynchronous-work/event-loop-timers-and-nexttick#setimmediate-vs-settimeout) explain the reason. +In that case, `console.log('Hello => number 1');` will first run because event loop only starts after call stack is cleared.The `nextTick` queue is processed before entering the next phase, which is why the `process.nextTick()` callback runs immediately after. + +The execution order of `serImmediate` and `setTimeout` can not be determined in the main module. For a detailed explanation, refer to [setImmediate vs setTimeout](https://nodejs.org/en/learn/asynchronous-work/event-loop-timers-and-nexttick#setimmediate-vs-settimeout). From c53b877121162872081783887cd405f59a3eeb69 Mon Sep 17 00:00:00 2001 From: kekekuli Date: Thu, 24 Apr 2025 23:50:56 +0800 Subject: [PATCH 3/7] fix: add a link for the "order of events" --- .../en/learn/asynchronous-work/understanding-processnexttick.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/site/pages/en/learn/asynchronous-work/understanding-processnexttick.md b/apps/site/pages/en/learn/asynchronous-work/understanding-processnexttick.md index 5e335de3aade3..b7fd8cca2780b 100644 --- a/apps/site/pages/en/learn/asynchronous-work/understanding-processnexttick.md +++ b/apps/site/pages/en/learn/asynchronous-work/understanding-processnexttick.md @@ -25,7 +25,7 @@ Calling `setTimeout(() => {}, 0)` will execute the function at the end of next t Use `nextTick()` when you want to make sure that in the next event loop iteration that code is already executed. -#### An Example of the order of events: +#### An Example of the [order of events](https://nodejs.org/en/learn/asynchronous-work/event-loop-timers-and-nexttick): ```js console.log('Hello => number 1'); From 3517c2a69c70eec7769391c35d2e98653c04e6be Mon Sep 17 00:00:00 2001 From: kekekuli Date: Fri, 25 Apr 2025 00:06:32 +0800 Subject: [PATCH 4/7] fix: use more clear words to summary --- .../en/learn/asynchronous-work/understanding-processnexttick.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/site/pages/en/learn/asynchronous-work/understanding-processnexttick.md b/apps/site/pages/en/learn/asynchronous-work/understanding-processnexttick.md index b7fd8cca2780b..2da1533c770ad 100644 --- a/apps/site/pages/en/learn/asynchronous-work/understanding-processnexttick.md +++ b/apps/site/pages/en/learn/asynchronous-work/understanding-processnexttick.md @@ -54,4 +54,4 @@ Running at order 3 or 4, setTimeout In that case, `console.log('Hello => number 1');` will first run because event loop only starts after call stack is cleared.The `nextTick` queue is processed before entering the next phase, which is why the `process.nextTick()` callback runs immediately after. -The execution order of `serImmediate` and `setTimeout` can not be determined in the main module. For a detailed explanation, refer to [setImmediate vs setTimeout](https://nodejs.org/en/learn/asynchronous-work/event-loop-timers-and-nexttick#setimmediate-vs-settimeout). +The execution order of `setImmediate()` and `setTimeout()` can very based on the execution contexts. For more information, refer to [`setImmediate()` vs `setTimeout()`](https://nodejs.org/en/learn/asynchronous-work/event-loop-timers-and-nexttick#setimmediate-vs-settimeout). From 8c8ec4ab25b163c8380287c4b38fecfa43a72afb Mon Sep 17 00:00:00 2001 From: kekekuli Date: Fri, 25 Apr 2025 09:49:34 +0800 Subject: [PATCH 5/7] fix: use doc link instead of example code --- .../understanding-processnexttick.md | 31 +------------------ 1 file changed, 1 insertion(+), 30 deletions(-) diff --git a/apps/site/pages/en/learn/asynchronous-work/understanding-processnexttick.md b/apps/site/pages/en/learn/asynchronous-work/understanding-processnexttick.md index 2da1533c770ad..bc61c0ae82c61 100644 --- a/apps/site/pages/en/learn/asynchronous-work/understanding-processnexttick.md +++ b/apps/site/pages/en/learn/asynchronous-work/understanding-processnexttick.md @@ -25,33 +25,4 @@ Calling `setTimeout(() => {}, 0)` will execute the function at the end of next t Use `nextTick()` when you want to make sure that in the next event loop iteration that code is already executed. -#### An Example of the [order of events](https://nodejs.org/en/learn/asynchronous-work/event-loop-timers-and-nexttick): - -```js -console.log('Hello => number 1'); - -setImmediate(() => { - console.log('Running at order 3 or 4, setImmediate'); -}); - -setTimeout(() => { - console.log('Running at order 3 or 4, setTimeout'); -}, 0); - -process.nextTick(() => { - console.log('Running at next tick => number 2'); -}); -``` - -#### Example output(possible): - -```bash -Hello => number 1 -Running at next tick => number 2 -Running at order 3 or 4, setImmediate -Running at order 3 or 4, setTimeout -``` - -In that case, `console.log('Hello => number 1');` will first run because event loop only starts after call stack is cleared.The `nextTick` queue is processed before entering the next phase, which is why the `process.nextTick()` callback runs immediately after. - -The execution order of `setImmediate()` and `setTimeout()` can very based on the execution contexts. For more information, refer to [`setImmediate()` vs `setTimeout()`](https://nodejs.org/en/learn/asynchronous-work/event-loop-timers-and-nexttick#setimmediate-vs-settimeout). +For more details on the order of events, refer to [Event loop](https://nodejs.org/en/learn/asynchronous-work/event-loop-timers-and-nexttick). From 2ec77d0ba186986abd444d7665faef5591c53036 Mon Sep 17 00:00:00 2001 From: kekekuli Date: Fri, 25 Apr 2025 10:28:40 +0800 Subject: [PATCH 6/7] fix: change the summary words --- .../en/learn/asynchronous-work/understanding-processnexttick.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/site/pages/en/learn/asynchronous-work/understanding-processnexttick.md b/apps/site/pages/en/learn/asynchronous-work/understanding-processnexttick.md index bc61c0ae82c61..5e4ebf39159bd 100644 --- a/apps/site/pages/en/learn/asynchronous-work/understanding-processnexttick.md +++ b/apps/site/pages/en/learn/asynchronous-work/understanding-processnexttick.md @@ -25,4 +25,4 @@ Calling `setTimeout(() => {}, 0)` will execute the function at the end of next t Use `nextTick()` when you want to make sure that in the next event loop iteration that code is already executed. -For more details on the order of events, refer to [Event loop](https://nodejs.org/en/learn/asynchronous-work/event-loop-timers-and-nexttick). +To learn more about the order of execution and how the event loop works, check out [the dedicated article](learn/asynchronous-work/event-loop-timers-and-nexttick) From d85af467cd829508cb60c03d3dc46c850780800e Mon Sep 17 00:00:00 2001 From: kekekuli Date: Sat, 26 Apr 2025 10:56:47 +0800 Subject: [PATCH 7/7] fix: fix error link --- .../en/learn/asynchronous-work/understanding-processnexttick.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/site/pages/en/learn/asynchronous-work/understanding-processnexttick.md b/apps/site/pages/en/learn/asynchronous-work/understanding-processnexttick.md index 5e4ebf39159bd..2b71a57b2eb2e 100644 --- a/apps/site/pages/en/learn/asynchronous-work/understanding-processnexttick.md +++ b/apps/site/pages/en/learn/asynchronous-work/understanding-processnexttick.md @@ -25,4 +25,4 @@ Calling `setTimeout(() => {}, 0)` will execute the function at the end of next t Use `nextTick()` when you want to make sure that in the next event loop iteration that code is already executed. -To learn more about the order of execution and how the event loop works, check out [the dedicated article](learn/asynchronous-work/event-loop-timers-and-nexttick) +To learn more about the order of execution and how the event loop works, check out [the dedicated article](https://nodejs.org/en/learn/asynchronous-work/event-loop-timers-and-nexttick)