Rxjs: incorrect behavior of cache()

Created on 15 Apr 2016  路  4Comments  路  Source: ReactiveX/rxjs

RxJS version: 5.0.0-beta.6

Code to reproduce:

Rx.Observable
  .fromPromise(new Promise((res) => res(true)))
  .map(() => 'abc')
  .do(() => console.log('LOG_1'))
  .cache()
  .do(() => console.log('LOG_2'))
  .flatMap(() => Rx.Observable.timer(500)
    .flatMap(() => Rx.Observable.throw('ERR')))
  .retry(3)
  .subscribe(() => {})

Expected behavior: LOG_1 should happen once and LOG_2 four times:

LOG_1
LOG_2
LOG_2
LOG_2
LOG_2

Similarly to:

Rx.Observable.timer(1000)
  .map(() => 'abc')
  .do(() => console.log('LOG_1'))
  .cache()
  .do(() => console.log('LOG_2'))
  .flatMap(() => Rx.Observable.timer(500)
    .flatMap(() => Rx.Observable.throw('ERR')))
  .retry(3)
  .subscribe(() => {})

Actual behavior: LOG_1 appears four times, moreover after retry the order of logs is reversed.

LOG_1
LOG_2
LOG_2
LOG_1
Uncaught ObjectUnsubscribedError
LOG_2
LOG_1
Uncaught ObjectUnsubscribedError
LOG_2
LOG_1
Uncaught ObjectUnsubscribedError

Additional information: Both code snippets generate: Uncaught ObjectUnsubscribedError after each retry. demo

bug

Most helpful comment

I'll look into this very soon.

All 4 comments

By any chance did anyone take a look at it? Is it a bug or am I doing something wrong?

I'll look into this very soon.

Just wonder if it may be _somehow_ connected to: #1466.

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

benlesh picture benlesh  路  3Comments

shenlin192 picture shenlin192  路  3Comments

Agraphie picture Agraphie  路  3Comments

benlesh picture benlesh  路  3Comments

matthewwithanm picture matthewwithanm  路  4Comments