I have a service that gets triggered to make calls on the backend How can I cancel previous ongoing requests to only get the last request result back my code is :
this.vehiclesService.getVehiclesByPage(currentState).subscribe(success => {
this.cache[backendPage] = true;
this.setPageResult({ ...success, page: backendPage, pageSize: pageInfo.pageSize * 10 });
});
I tried to add a debounceTime like this but it didn't seem to work
this.vehiclesService.getVehiclesByPage(currentState).pipe(debounceTime(500)).subscribe(success => {
this.cache[backendPage] = true;
this.setPageResult({ ...success, page: backendPage, pageSize: pageInfo.pageSize * 10 });
});
I believe that a switchMap should do the trick yet I don't know how to combine it with my code Can anyone show me how to add it ?