Rxjs, how to find out how many subscribers are observed?

When I have several subscribers to one observable, for example:

const myInterval = Rx.Observable.interval(500); const subscriptionOne = myInterval.subscribe(val => doSomething()); const subscriptionTwo = myInterval.subscribe(val => doSomething()); 

How do I know how many subscribers are still registering in myInterval observable? Do I need this information, for example, to prevent memory leaks if I forget to unsubscribe from one of them?

+5
source share
1 answer

When using angular 2, you should use the asynchronous channel as much as possible, as this will automatically disable you when your component is destroyed.

It is said. Your gap here is observed cold. Value, a value producer will be configured for each subscription. This means that every time a new subscription is created. Therefore, knowing how many signatures you still need to have to watch the cold is a question that you cannot answer.

I am afraid that the only thing you can do is to manage your subscriptions in their pure form and rely on angular as much as possible.

+1
source

Source: https://habr.com/ru/post/1258552/


All Articles