Readings: Callbacks

Javascript Callback Pattern

Node.js made the decision to have all asynchronous events be handled using error first callbacks. The main advantage of this is that all asynchronous methods have a consistent interface. This means that when you are working with asynchronous Node.js code, you can always assume how the callback is going to be formatted, making your life as a developer much easier!

Having a consistent callback interface has also made it possible for libraries to be written that assist Javascript developers in handling complex async code!

A callback says, “Hey, Javascript, you go ahead do some work. I don’t care how long it takes, and I’m going to go ahead and keep on working … but when you’re all done, here’s a function I want you to run.”

That function is the callback, and it operates on a nicely standardized signature.

Defining an Error First Callback

Additional Resources