From 176a3960e2c7fec8ad73b840da5a99b6a772b2da Mon Sep 17 00:00:00 2001 From: legendAhsan Date: Mon, 19 Aug 2024 20:04:41 +0500 Subject: [PATCH] fix: improved understanding of setImmediate and setTimeout output --- .../understanding-processnexttick.md | 11 ++++++++++- 1 file changed, 10 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 5ae90951d507b..434508006855c 100644 --- a/apps/site/pages/en/learn/asynchronous-work/understanding-processnexttick.md +++ b/apps/site/pages/en/learn/asynchronous-work/understanding-processnexttick.md @@ -51,4 +51,13 @@ Running before the timeout => number 3 The timeout running last => number 4 ``` -The exact output may differ from run to run. +The output aforementioned holds true in ES Modules, e.g. mjs files, but keep in mind in CommonJS case, the output may be different: + +```bash +Hello => number 1 +Running at next tick => number 2 +The timeout running last => number 4 +Running before the timeout => number 3 +``` + +This is because the execution order of setImmediate and setTimeout is undeterministic in CommonJs.