Reactive-Extensions / RxJS

The Reactive Extensions for JavaScript
http://reactivex.io
Other
19.49k stars 2.1k forks source link

Bug with .share operator? #1489

Open jaidetree opened 7 years ago

jaidetree commented 7 years ago

If you have code like this, and you can imagine several of these streams\subscriptions are created throughout the lifecycle of an application. An error is thrown when trying to dispose of all the streams raising an "Object has been disposed" error.

I've attempted to boil it down to the simplest repro case:

let source = Rx.Observable.interval(200)
  .debounce(150)
  .finally(() => console.log('killing source'))
  .take(50)
  .publish();

let subject = new Rx.Subject();

let sourceB = Rx.Observable.interval(500)
  .map(x => x * 100)
  .take(25)
  .subscribe(subject);

let subscriberA = source
  .finally(() => console.log('killing a'))
  .subscribe(x => console.log('A', x));

let subscriberB = source
  .merge(subject)
  .map(x => String.fromCharCode(x + 32))
  .finally(() => console.log('killing b'))
  .subscribe(x => console.log('B', x))

let connection = source.connect();

Rx.Observable
  .timer(5000)
  .subscribe(() => {
    connection.dispose();
    subject.dispose();
  })

Is running from here: https://codepen.io/jayzawrotny/pen/JJbxgE?editors=0011

I would expect that the source gets killed, a & b get killed and then no more data is requested from the subject which will be disposed at that time as well.