Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug on whether observable is unsubscribe

how can i test whether the observable is unsubscribe after subscription. I am developing in ionic2/angular2.

I am expecting typing something like this in chrome developer mode and it will return value: observableName.isSubscribe()

like image 428
eulercode Avatar asked Sep 14 '17 14:09

eulercode


2 Answers

You can have a subscription and check closed parameter.

let subscription = observable.subscribe(() => {})

if (!subscription.closed) {
  //subscribed
} else {
  //not subscribed
}
like image 89
alexKhymenko Avatar answered Oct 11 '22 00:10

alexKhymenko


As sebaferreras told in the last comment, you can just use the closed property;

So, for example:

const sub$ = new Subject();
sub$.unsubscribe();
sub$.closed //true;
like image 39
Mathias Gheno Azzolini Avatar answered Oct 11 '22 01:10

Mathias Gheno Azzolini