How it works...
We construct an array of promises, and then push into that array both our getPosts method and our new getBlogMetadata method, both of which return promise HTTP requests to our API. We then register a callback--known as all--on this promise array, which will fire after all the promises in our array have completed. When the promises are completed, our data will be returned as an array of results, with each index matching the index of the original promise array. In this case, the first array value will be our blog posts data, and our second value will be our blog metadata.
This sort of concurrent request management can come in handy if you have multiple pieces of data that all need to be retrieved before updating your application's ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access