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 state. However, linking requests together like this can also cause your application's loading performance to suffer by making your total callback time equal to your longest running API request. It's important to be aware of these performance trade-offs when deciding whether to handle multiple requests as one concurrent request or multiple asynchronous ones.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.223.195.101