Thursday, December 30, 2021

How Asynchoronus javascript works behind the scene

We already know when a function is called it invoked into execution stack of javascript engine.
When the work is finished it popped from the stack . But when asynchoronus js callback is in 
your code then the invoked into WEB API section of javascript engine and the callback is wait 
into the Web API until the wait is finished. But the other function will push into stack and 
after finished will popped from the stack .After then the callback will enqueue into message
queue and will pushed into execution stack if the stack is empty. Though it is called in stack and 
asynchoronus js is run in Web API so it will not harm our normal execution .That's why as
asynchoronus is non-block. Event loop will always check if stack is empty and the function is 
in Message queue.






No comments:

Post a Comment

Fluent interface pattern

 public class UserConfigurationManager {     private String userName;     private String password;     private UserConfigurationManager() { ...