Skip to content

Commit

Permalink
fix: improved understanding of setImmediate and setTimeout output
Browse files Browse the repository at this point in the history
  • Loading branch information
legendAhsan committed Aug 19, 2024
1 parent 9af1dcb commit 176a396
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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.

0 comments on commit 176a396

Please sign in to comment.