refCount method

  1. @override
Observable<T> refCount ()
override

Returns an Observable that stays connected to this ConnectableObservable as long as there is at least one subscription to this ConnectableObservable.

Implementation

@override
Observable<T> refCount() {
  ConnectableObservableStreamSubscription<T> subscription;

  _subject.onListen = () {
    subscription = ConnectableObservableStreamSubscription<T>(
      _source.listen(_subject.add, onError: _subject.addError),
      _subject,
    );
  };

  _subject.onCancel = () {
    subscription.cancel();
  };

  return _subject;
}