Given our understanding of what async is, how the callback pattern manages async, and some of the deficiencies of the callback pattern, let’s dive into another, newer pattern — promises.
As with callbacks, for a new developer, it can be difficult to sift through the massive amount of information available online. For the benefit of anyone else newly exposed to promises, in this post I’ve attempted to cull the resources and posts that I have found most enlightening through my own learning.
What are promises all about?
Before diving into code, what are promises, conceptually? There are many out there, but I found Kyle Simpson’s ‘cheeseburger’ metaphor to be illuminating. If you prefer to hear an explanation, watch the video embedded below (15:20 mark). If you’d rather read, check it out in ‘You Don’t Know JS‘.
Getting our feet wet
Promises and callbacks: key differences
James Knelson’s Introduction to ES6 Promises – The Four Functions You Need To Avoid Callback Hell provides a succinct distillation of some core differences between promises and callbacks — I think this is helpful to pull everything together more clearly after already being acquainted with both.
Recently a friend and I pulled together a snippet that goes over constructing a new promise, using a promise to wrap another async action, and a direct comparison of a callback example and its promise alternative.
I hope this was helpful in narrowing some of the available content out there. Please leave a comment if you see any needed correction — or if there’s a resource out there that was really illuminating for you.