Skip to content

Instantly share code, notes, and snippets.

@mfrachet
Last active April 21, 2021 08:47
Show Gist options
  • Save mfrachet/9146123e084badaa79135d6ae1d294ed to your computer and use it in GitHub Desktop.
Save mfrachet/9146123e084badaa79135d6ae1d294ed to your computer and use it in GitHub Desktop.
I don't get the order
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