You don't have to strugle about what is happening as in your application you just need to know which event will be called and when.
Remeber below sequance.
1) process.nextTick();
process.nextTick(functionBlockToExecute.); //Function here will be called first no matter it's place where it is declared but only thing is matter that it should be declared along with below other functions than it will execute first
2) Promise => resolve.
new Promise((resolve, reject) => {
resolve('bar'); // Promise resolution will be second in stack to be callled.
});
3) Promise => then.
new Promise((resolve, reject) => {
resolve('bar');
}).then((resolve) => {
console.log(resolve);
process.nextTick(zoo); //Here when a promise resiolved then will be called.
});
4) setImmediate(functionCall)
setImmediate(baz); //However setImmediate execute as soon as possible it still executed after above 3 scenarios.
Remember above all are immediate calls and are compared with each other when we are working with such a multiple immediate function calls.
Top comments (1)
Add to the discussion