Reactive-Extensions / RxJS

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

Using `retry()` with `Rx.Observable.spawn()` results in undefined values #1333

Open eschwartz opened 8 years ago

eschwartz commented 8 years ago

RxJS version: 4.1.0

Code to reproduce:

Rx.Observable
  .spawn(function*() {
    return 'A';
  })
  .map((val) => {
    console.log(`map: ${val}`)
    throw new Error('fail');
  })
  .retry(2)
  .subscribe(
    (val) => console.log(`onNext: ${val}`),
    (err) => console.log(`onError: ${err.message}`),
    (complete) => console.log('complete')
  );

Expected behavior:

map: A
map: A
onError: fail

Actual behavior:

map: A
map: undefined
onError: fail

Additional information:

Using Rx.Observable.spawn causes the second attempt to emit undefined instead of "A".

Note that this works as expected, if using Rx.Observable.fromPromise instead:

Rx.Observable
  .fromPromise(() => Promise.resolve('A'))
  .map((val) => {
    console.log(`map: ${val}`)
    throw new Error('fail');
  })
  .retry(2)
  .subscribe(
    (val) => console.log(`onNext: ${val}`),
    (err) => console.log(`onError: ${err.message}`),
    (complete) => console.log('complete')
  );

// map: A
// map: A
// onError: fail
eschwartz commented 8 years ago

I noticed when running this in CodePen, that it works as expected with TypeScript, but it fails when using plain JS.

This may explain why it's not caught by existing test coverage.