There are lot of discussions on this topic but still i am not able to figure out which one i need to use for my usecase. I have a method that needs to be called every 3 seconds to get updated stock details .
ngOnInit() {
this.getUpdatedStock(); // to get data while loading page for first time
this.interval = setInterval(()=> {
this.getUpdatedStock();
},3000)
}
whereas getUpdatedStock() calls the service and do some manipulations before rendering data .
getUpdatedStock(){
this.stockService.getStockData().subscribe((data)=> {
this.latestStock = data ;
// few lines of code to highlight table headers based on response
})}
As expected the setInterval() , the request gets stacked up if there is delay in response and also the calls are not happening after 3 seconds since the last response is received . Then i found following thread which explains the use of rxjs methods
Why would I use RxJS interval() or timer() polling instead of window.setInterval()?
There also some suggestions been made not to go with rxjs for that usecase as it may increase bundle size . Now i am thinking of which one to use for my usecase . I dont want calls to happen until i receive response from previous request and it should 3 seconds since i received the response . Is it possible to do with setInterval() itself or i have to go with rxjs . If i have to go with rxjs timer() or interval() can someone please tell me how that can be done as i am not calling the service directly . I am calling method within which service call is triggered and data manipulations are done .