When I try to use Promise.all to call the same internal endpoint multiple times the data returned from each promise in a order different every time. For additional information: These endpoints perform significant DB queries to retrieve decently large arrays of data (10X20 array of strings)
Why is this happening?
Isn't Promise.all suppose to run sequentially. Is this issue due to the fact that I'm calling the same endpoint every time?
I have not encountered this issue before when using Promise.all to call multiple different endpoints
// endpoint return "1"
getCall1(){
return new Promise((resolve, reject) => { internal_api.get(`get/users/`, data = {'name': 1})
.then(res => {resolve(res);})
.catch(err => {reject(err);})
});
}
// endpoint return "2"
getCall2(){
return new Promise((resolve, reject) => { internal_api.get(`get/users/`, data = {'name': 2})
.then(res => {resolve(res);})
.catch(err => {reject(err);})
});
}
// endpoint return "3"
getCall3(){
return new Promise((resolve, reject) => { internal_api.get(`get/users/`, data = {'name': 3})
.then(res => {resolve(res);})
.catch(err => {reject(err);})
});
}
getAllCalls(){
Promise.all([
this.getCall1(),
this.getCall2(),
this.getCall3(),
]).
.then(([call1, call2, call3]) => {
console.log(call1, call2, call3)
})
.catch();
Run #1 console logs
2 1 3
Run #2 console logs
3 1 2
Run #3 console logs
1 1 2
Run #4 console logs
1 2 3
Why is this happening?
Isn't Promise.all suppose to run sequentially. Is this issue due to the fact that I'm calling the same endpoint every time?
I have not encountered this issue before when using Promise.all to call multiple different endpoints