I have a scenario where I need to call a service method(which will call HTTP post method) repetitively until I get the results and for that I am using interval.
In below code the getReportResultsList(id)
method will be get called in the interval of 100 ms.
The problem is, the server may take 300 ms time to process the first request and return the results. But at the same time 2 more requests are going to the server to get the results because of interval(100). So after getting the results from the first request i don't want to process the unexpected 2nd and 3rd requests response results.
So I don't want to process the 2nd and 3rd responses. Can any one know how to to deal with these out of order responses?
Thanks.
let subscriber = Observable.interval(100).subscribe(() => {
this.reportService.getReportResultList(id)
.subscribe(result => {
this.reportResults = result;
if (this.reportResults) {
this.prepareViewData(result);
subscriber.unsubscribe();
}
});
});