I have an Angular project where HTTP-searches are started by typing in an input field. This is done like the examples on the web with following code (simplified):
this.form.valueChanges.pipe (
debounceTime (this.dueTime),
distinctUntilChanged (compare),
switchMap (() => async$()
);
function async$ {
count++;
return load$ ().pipe (tap ((response: T) => {
count--;
...
},error => {
count--;
...
}
}
}
This works fine, but everytime async$
is started, a counter will be increased and when it is finished, the counter will be decreased again.
So when the subscription is unsubscribed by switchMap
, the count is increased but not decreased again, because the success or error method are never called.
So my question is: is there a possibility to get noticed of the cancellation of the subscription so that I can decrease the counter?
It is not an option to put the count logic out of async$
because the function is used elsewhere.