I am using ES6 JavaScript and making API calls that are reliant on the order in which they are returned. The http client is Axios. A colleague has instructed me to use Promise.all()
. It works and I know it's guaranteed to, but I am unsure how it can be guaranteed that the results are in order. My understanding is that asynchronous requests are not guaranteed! My simplified code is:
Promise.all([
axios.get('/cars'),
axios.get('/road-conditions')
]).then(values => {
this.cars = values[0]
this.roadConditions = values[1]
})
I would like to understand how values
knows which request is which. Is this a special feature with Axios?