Node.js & Event Loop Flashcards
JS Event loop
concurrency model built on top of the core JS in a browser ( or programming environment) and accessed through browser APIs
Basic Browser Architecture
Left Column: Core JS
Right Column: WebAPIs
Bottom footer: callback queue
Above footer: event loop
Browser Structure: Core JS
Heap - objects allocated in heap, unstructured region of memory
Stack (call stack)- represents single thread for JS code execution
Browser Structure: WebAPIs
Built into browser, able to expose data from the browser and surrounding computer environment. Not part of JS itself. i.e. DOM, Ajax, setTimeout
Browser Structure: Callback (task) queue
Accepts completed process code from the WebAPI, and ferries the code to the main call stack for code execution based on the event loop
Browser Structure: Event loop
Checks if the main call stack is empty, and if any processes in the callback queue are due to be put back onto the callstack. Must wait until call stack is clear to push reinsert processes in queue.
Node.js
An asynchronous, event driven runtime environment for JS that allows for non-blocking I/O using a concurrency model like the browser JS event loop.