Last active
April 21, 2021 08:47
-
-
Save mfrachet/9146123e084badaa79135d6ae1d294ed to your computer and use it in GitHub Desktop.
I don't get the order
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { setTimeout: st } = require("timers/promises"); | |
/* | |
* Permutating the call to the timers setTimeout and the regular setTimeout permutates the order of apparition | |
* HOWEVER, "Regular promise" will always be shown first, even if declared last (micro task) | |
* setTimeout is still a macrotask then? | |
*/ | |
function main() { | |
st(0).then(() => { | |
console.log("With promise"); | |
}); | |
setTimeout(() => { | |
console.log("Regular setimeout"); | |
}, 0); | |
Promise.resolve().then(() => console.log("Regular promise")); | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment