Reactive-Extensions / RxJS

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

do instead of subscribe : Lost events #1423

Closed maxime1992 closed 7 years ago

maxime1992 commented 7 years ago

Environment

RxJS v5.2.0

What's the problem ?

When using do instead of subscribe at the end of an observable chain, we are not notified (sometimes ?)

Plunkr repro

@victornoel helped me to create a minimal repro (👍) of the issue and a Plunkr is available here : https://plnkr.co/edit/KjaL14tSbrns7uLqSZxO?p=preview

Code repro

const { Observable, ReplaySubject } = Rx

let cpt = 0

const rs = new ReplaySubject(1)

rs
  // should print for every `next`
  // * COM 1
  .do(console.log)
  .subscribe()

const next = () => {
  const n = cpt++
  console.log('next', n)
  rs.next(n)
}

const func = () => {
  rs
  .first()
  // * COM 2
  .do(_ => next())
  .subscribe()
}

// SHOULD DISPLAY
// next 0
// 0
next()

// SHOULD DISPLAY
// next 1
// 1
func()

// SHOULD DISPLAY
// next 2
// 2 --> !!! DOES NOT APPEARS !!! <--
next()

/**
 * 
 * COM 1 & COM 2
 * 
 * To make it work as expected :
 * - Replace the `do` by a `subscribe`
 * - Remove the subscribe right after
 * 
 */
paulpdaniels commented 7 years ago

Wrong repo https://github.com/ReactiveX/rxjs

maxime1992 commented 7 years ago

@paulpdaniels thx. Closing in favor of : https://github.com/ReactiveX/rxjs/issues/2406