Video Ristretto: Promises, Ben Teese
Asynchronous programming in JavaScript has until relatively recently been a simple matter, using callback functions that get triggered once a process is completed. But as the things we build with Web technologies have become more and more sophisticated, it’s been obvious for some time this isn’t good enough anymore.
A couple of weeks back we looked at one approach to asynchronous JavaScript in ES2015 (AKA ES6), the async
and await
features of the language. This week we look at a complementary approach, promises.
In short, a promise is an object returned by a function that executes asynchronously. In essence, it allows asynchronous operations to be used similarly to synchronous functions, assigning a return value (the promise) to a variable, which resolves to a value once the asynchronous function actually completes (or an error value if there is a failure of some kind).
Promises are part of ES6, and are widely supported (in all modern browsers for some time, with the exception of Internet Explorer up to 11, although Edge does support promises). More importantly, newer asynchronous DOM APIs like Service Worker return Promises, so there’s no avoiding them even if you wanted to into the future!
As you might have guessed, this week’s Video Ristretto is 20 minutes on Promises from Ben Teese at our Code 2015 conference. A really stand-out presentation; cue it up and watch it on your commute at home, your lunch break, even your coffee break!
And for more like this, Code 2016 is on in both Sydney and Melbourne in late July and early August. Why not join hundreds of your peers in the front-end world there?
Further Reading
Domenic Denicola asks “What is the point of promises?“. His point is it’s much more than simply managing callbacks more nicely. MDN on Promises will give you an in-depth overview of the technology.
Further Watching
James Hunter from Code 15 on async
and await
Domenic Denicola again, from again Code 2015, on the broader idea of asynchronous programming with JavaScript. A fantastic presentation.
Want more?
Like to see and read more like this? Be the first to score invitations to our events? Then jump on our once-a-week mailing list where we round up the week’s best reading and watching on all things Web. And you’ll get a complimentary digital copy of our brand new magazine, Scroll.
Great reading, every weekend.
We round up the best writing about the web and send it your way each Friday.