Alternatives for managing asynchronous calls
We've now seen the general pattern for performing multiple asynchronous operations at once. While it wasn't too difficult to keeping track of the pending requests by hand, it can become tiresome if you have to do this often. It can also become more complex if you do not have as simple a starting point as the length of an array; for example, if you only perform a request when certain conditions are met, or if you perform more than one request per item.
There are a number of solutions available to help you manage asynchronous control flow. We'll look at a few of these and try applying them to our application. These are completely optional! There's nothing wrong with the code we just wrote, and in subsequent chapters we will continue to use that version. But it's a good idea to know what your options are, especially if you end up working on an application with a large number of complex asynchronous operations.
Promises
The first solution we'll explore...