Reactive-Extensions / RxJS

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

Observable.generate with Promises behavior #1407

Open derekstavis opened 7 years ago

derekstavis commented 7 years ago

I have been trying some code snippets at node REPL and I've stumbled into an issue with Observable.generate usage.

The following snippet works:

rx.Observable.generate(
  { v: 1 },
  o => o.v < 100,
  o => ({ v: o.v + 1 }),
  o => o
).subscribe(
  console.log.bind(null, 'next'),
  console.log.bind(null, 'error'),
  console.log.bind(null, 'completed')
)

When adding Promises, the analogous works partially:

rx.Observable.generate(
  { v: 1 },
  o => o.v < 100,
  o => Promise.resolve({ v: o.v + 1 }),
  o => o
).subscribe(
  console.log.bind(null, 'next'),
  console.log.bind(null, 'error'),
  console.log.bind(null, 'completed')
)

With the observable finishing with a single next before receiving the completed callback.

Is it by design that Promises finish the generate observable?

Thanks!