help
help copied to clipboard
Order of nextTicks and microtasks
Details
When I was writting some code I bump into incorrect as I think behaviour of nextTick queue and microtask queue.
Ok, example of the code will be the following:
process.nextTick(() => console.log(1));
Promise.resolve().then(() => console.log(2));
Promise.resolve().then(() => console.log(3));
setImmediate(() => {
Promise.resolve().then(() => console.log(4));
process.nextTick(() => console.log(5));
});
it will output:
2
3
1
5
4
However, If I'll wrap that code into setTimeout you will see another order of outputs:
1
2
3
5
4
So why do I see that microtask will be first rather than nextTick without wrapping by setTimeout?
Node.js version
v18.9.0
Example code
All has been described in details section.
Operating system
Windows 10
Scope
Runtime
Module and version
There are no modules in usage
I am not able to replicate the code results which you are running without encapsulating in set Timeout. Please provide some more information!!
@siddiq-rehman code was performed like .mjs
It seems there has been no activity on this issue for a while, and it is being closed in 30 days. If you believe this issue should remain open, please leave a comment. If you need further assistance or have questions, you can also search for similar issues on Stack Overflow. Make sure to look at the README file for the most updated links.
It seems there has been no activity on this issue for a while, and it is being closed. If you believe this issue should remain open, please leave a comment. If you need further assistance or have questions, you can also search for similar issues on Stack Overflow. Make sure to look at the README file for the most updated links.