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

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.

Latest comments (1)

Collapse
 
sindouk profile image
Sindou KonΓ©

Add to the discussion

We want your help! Become a Tag Moderator.
Fill out this survey and help us moderate our community by becoming a tag moderator here at DEV.