Tuesday, July 5, 2016

Node.js - 1

Node.js = Javascript Runtime

Built on top of Chrome's V8 Javascript Engine.

And? And it also uses libuv. So while Node.js is single threaded from development perspective, it's actually using libuv internally for threading, implementing thread pool and managing file system events. 

How does async programming work in Node.js?

Node.js applications act on events i.e. the flow of the application is governed by events (like ) . Node.js manages this asynchronously via event loop.

What's event loop?
That explanation requires another post. Event loop essentially takes up any pending tasks in task queue/ callback queue and puts them on stack.

All functions to be executed by V8 are pushed to a stack and popped when they are executed. Event Loop will wait for the Stack to be empty and if it's so it will push a function from callback queue to stack.

How event loop works is explained beautifully by Philip Roberts at https://youtu.be/8aGhZQkoFbQ


And checkout the tool demoed in the talk above at  latentflip.com/loupe

No comments:

Post a Comment