Is there a way to avoid repetitive function calls within a recursive function?
Take a look at the following code snippet:
loadFinalData(id, color){
this.data = this._test.getUrl(id, "white");
this.dataHover = this._test.getUrl(id, "blue");
}
private flux: Subscription;
loadData(id, color) {
if(this.flux) this.flux.unsubscribe();
this.flux = this._test.getData(id, "white")
.subscribe(
res => this.loadFinalData(id, "white"),
err => setTimeout( _ => this.loadData(id, "white"), 5000 )
)
};
In this scenario, we are recursively calling the loadData function.
The issue arises from the fact that the error function in the subscribe() block triggers every 5 seconds and does not stop (even when using unsubscribe()).