I have multiply async calls. For example four of them
this.lazyLoadData();
this.lazyLoadData();
this.lazyLoadData();
this.lazyLoadData();
the problem is that every http request can take different time. In every request i am sending different query parameters to fetch paginated data on backend.
So in this case the first this.lazyLoadData
can finish sometimes later then the second one -
depending on the paginated results on the backend.
So to prevent that behaviour i tried to use async and await
await this.lazyLoadData();
await this.lazyLoadData();
await this.lazyLoadData();
await this.lazyLoadData();
async lazyLoadData(cb?) {
const filtersParam: any = {
page: this.filterService.dashboardPage,
size: 25,
}
let response = await this.processMonitorService.monitoring(filtersParam);
response.then(data => {
console.log('maked http call');
});
...
}
but the problem is that still, even i use async and await - this four http calls does not happen in order.
So in duration of one second i am calling four times lazyLoadData
, i await every result there
but responses does not come in order. So sometimes again third gets executed before the second one etc...
How can i solve this ?