1
\$\begingroup\$

I am creating a web application using Angular 8. This application is all about talking to the stock markets server and getting the Live updates every second. I have one query here. Below is my code:

setInterval(()=> {
this.GETDATA_NSE_EQ_LIVE();},
1000);

 GETDATA_NSE_EQ_LIVE():void{
      this._NSELiveFeedComponent.getData_nse_eq_live(this.stockSymbol)
          .subscribe((nse_eq_live_symbol_data) => this.Nse_Eq_Live_Symbol_data = nse_eq_live_symbol_data,
                     (err) => console.log(err));
    }

As we can see that i am using setInterval() method and i am calling GETDATA_NSE_EQ_LIVE() function in every second. This means that i am subscribing to getData_nse_eq_live(this.stockSymbol) method every second. How can i reuse the object once it is subscribed for the first time rather than subscribing it for every second? Also, is there any better approach than using setInterval() function for getting the stock updates every second?

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.