JavaScript Internal Architecture
Posted By : Shashwat Gupta | 29-Dec-2017
Non-blocking I/O
In js, aprox all Input and output operation is non-blocking including like HTTP requests, database operations and file system reads and writes etc in js single thread of execution asked at runtime to perform an operation, providing a callback function and then goes out for performing other operations . once the operation has been callback called after few mili sec. function changeHeaderDeferred() { var header = document.getElementById("header"); setTimeout(function changeHeader() { header.style.color = "red"; return false; }, 100); return false; } changeHeaderDeferred(); js is eventDriven interaction model differs from the request and response model However, this is but one approach
Event loop
The event loop is basically a loop which checks that "is rendered HTTP request is blocking or non-blocking and second work is check the call stack list .."is call stack empty or not " if event loop found any blocking HTTP request then it will transfer that Http request to thread pool with a callback and message and if event loop not found any Http request then it will compute and then response back to the Request Caller and whing checking
Lets look out the event loop code :
(queue.waitForMessage())
{
queue.processNextMessage();
}
queue.waitForMessage()
waits synchronously for a message to arrive if there is none currently.
Call Stack
Call stack is basically like a stack which contains all request from Request caller . if any Request caller hit the http request which contain any http verb like post ,get ,put or delete ..firstlt comes into the call stack
Task Queue
every callback which return from thread pool goes to firstly on task queue then every loop check that queue..if any callback will be available there then event loop task the callback ..execute code correspondingly
Web Apis
Every blocking request handled by web apis it returns callback after completion of blocking request with an callback and message
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Shashwat Gupta
Shashwat is a bright Mean Stack Developer . He has good experience in development of complex UI's of web application and hybrid mobile applications.