What the hell is nodejs call back ?




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/package/async that can be used to acheive the same result



Comments

Anonymous said…
What is the best casino site in India? | Lucky Club
The number 1 casino site with the best bonuses and the fastest payouts for slots, table games, video poker, luckyclub.live live dealer and more!

Popular posts from this blog

Validate Cognito tokens in Kong

Tracing Requests in AWS Serverless Applications

Leveraging AWS Elasticsearch