Controlling sequential asynchronous operations with async/await and Promises
Promises were introduced in ES2015 (ES6), along with other modern data structures.
For those familiar with JavaScript prior to ES2015, asynchronous behavior was modeled with callback-based interfaces, for example, request(url, (error, response) => { /* do work with response */ })
. The key issues that Promises resolved were the chaining of asynchronous requests and issues around managing parallel requests, which we’ll cover in this section.
ES2016 included the initial specification for the async/await syntax. It built on top of the Promise object in order to write asynchronous code that didn’t involve “Promise chains,” where different Promises are processed using the Promise().then
function. Promise functionality and async/await interoperate nicely. In fact, calling an async function returns a Promise.
We’ll start by showing how to use Promises to manage sequential...