Posts

Showing posts from November, 2017

What the hell is nodejs call back ?

Image
Callback is an asynchronous function. A callback function is called at the completion of a given task. Node makes heavy use of callbacks. All the APIs of Node are written in such a way that they support callbacks. Usually there are two way to write node functions - Blocking Code & Non-Blocking Code. Both of them have their own use cases. Non-Blocking code means the functions are executed parellelly (asynchronously) which is preferred when performance is a key factor (for example think of UI, where widgets gets loaded parellelly). Node scripts that use callbacks is hard to get right intuitively.  A lot of code ends up entagled and becomes hard to understand, debug. Typical sequential function using callback would look like same function when you want to execute parellely would look like Above scripts are example of creating your own functions however there are npm libraries https://www.npmjs.com/packag...