Suppose there are two web services.
We need to make requests to both of them.
And we have to wait till both requests are fulfilled.
Let’s launch three timers.
Two timers for two web services separately and one for all.
Let’s make a geo request.
After this request is fulfilled we log the timer.
And then make the drink request.
And log the timer.
Both the requests will start almost simultaneously.
But they will be fulfilled for different times.
So we have to wait for it all.
To do this we need the Promise object and the all method.
The all method has one iterable parameter: array of promises.
After all promises are fulfilled we can get the array of results.
Let’s do it.
First comes “drink”.
Then comes “geo”.
And here you are.
After all requests are fulfilled we have got the results.