DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 964,423 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Ajay Baraiya
Ajay Baraiya

Posted on • Updated on

Event Loops Immediate Calls #JS Quick Notes.

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
Enter fullscreen mode Exit fullscreen mode

2) Promise => resolve.

new Promise((resolve, reject) => {
    resolve('bar'); // Promise resolution will be second in stack to be callled.
  });

Enter fullscreen mode Exit fullscreen mode

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.
  });

Enter fullscreen mode Exit fullscreen mode

4) setImmediate(functionCall)

 setImmediate(baz); //However setImmediate execute as soon as possible it still executed after above 3 scenarios.
Enter fullscreen mode Exit fullscreen mode

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)

Collapse
 
sindouk profile image
Sindou KonΓ©

Add to the discussion

"I made 10x faster JSON.stringify() functions, even type safe"

☝️ Must read for JS devs