I am making http requests. When the request is done - with call back i am calling another function where the data from the async call is needed to make my logic.
On every call of my http request in lazyLoadData
i am making new page requests for data - so page 1 with 25 records, page 2 with the next 25 records from backend etc...
getData() {
this.lazyLoadData(this.testing.bind(this));
this.lazyLoadData(this.testing.bind(this));
}
lazyLoadData(cb?) {
// MY HTTP REQUESTS
let response = axios...
cb && cb();
}
testing(data) {
// my data arraived
}
if i call just once
this.lazyLoadData(this.testing.bind(this));
then everytjing works fine, when the http request is done, my callback - the testing functions
is called and i get the data.
But when i make call for example
two or more times
getData() {
this.lazyLoadData(this.testing.bind(this));
this.lazyLoadData(this.testing.bind(this));
this.lazyLoadData(this.testing.bind(this));
this.lazyLoadData(this.testing.bind(this));
}
sometimes call 2 - the second this.lazyLoadData(this.testing.bind(this));
is executed quicker then the first and i get my data mixed up. Because after i make the http request and i get, i am pushing that values in one global array with which my table is filled up.
And the data is not in order, so sometimes array contains first the data 25 records
from
page 2, then page 1, page 3 etc...
How can i prevent this ?