JavaScript has a love-hate relationship with asynchronous code. The language loves to let you make asynchronous calls and developers start to hate JavaScript because it's easy to create a giant mess. There are a lot of great patterns for handling asynchronous callbacks, of course. But it’s tempting to just hack some nested callbacks in place and end up with a giant monolithic sideways Christmas tree of doom doing that.
One of the many patterns and tools available for solving this problem is that of promises. There’s a lot of great work happening with JavaScript promises these days, and a lot of tools are taking advantage of them to give you more opportunity to clean up your code.
To that end, I recently found myself with a nasty mess of callbacks in a project that I’m building with Icenium Everlive. I needed to change the flow of code and add some new features, but I found myself stuck. I couldn’t understand the code that I had written. That is definitely not a good situation to be in. So I set out to solve it and once I realized that the Everlive JavaScript SDK provides promises to work with, the solution became clear to me. So I solved the problem, recorded my solution as a quick screencast, and am sharing that with you now!
There’s a lot of great information on promises out there. If you’re not familiar with them, I’d recommend reading more. Here are a few resources that should get you down the path of theory as well as using them.
About the Author
Derick Bailey is a Developer Advocate for Kendo UI, a developer, speaker, trainer, screen-caster and much more. He's been slinging code since the late 80’s and doing it professionally since the mid 90's. These days, Derick spends his time primarily writing javascript with back-end languages of all types, including Ruby,