I have an Angular (9) frontend with nestjs backend rest api (in nodejs) The endpoint I call in the backend does some fairly complex operations and it takes about 2 min to respond. In the frontend I use subscribe to subscribe to the response like this:
this.metaService.subscribe(
result => {
//Handle result
},
error => {
this.subscription.unsubscribe();
console.error('Error: ' + error);
},
() => {
this.subscription.unsubscribe();
console.error('Completed');
});
The problem is that in the backend it starts executing code over and over again. Note that it does not execute the http call again (I can see this from the network tab in Developer tools), it stays in Pending all the time) It seems this works if I do
.pipe(take(1)).subscribe(
then it does not do the looping in the backend but it immediately completes the subscription (and the http is in cancelled state in network tab) I am running this in my localhost on a windows machine (linux subsystem). Node version is 12.14.1
Does anyone what is causing this and how to fix it ?
-Jani