添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement . We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account Observable.race() completes immediately when one of its sources complete before emitting any item #2641 Observable.race() completes immediately when one of its sources complete before emitting any item #2641 martinsik opened this issue Jun 5, 2017 · 4 comments .subscribe(console.log, null, () => console.log('complete'));

http://jsbin.com/nuzifo/edit?html,js,console

Expected behavior:

complete

Actual behavior:

complete

Additional information:

Maybe this isn't a bug but the documentation for Observable.race() says (https://github.com/ReactiveX/rxjs/blob/master/src/operator/race.ts#L18):

Returns an Observable that mirrors the first source Observable to emit an item from the combination of this Observable and supplied Observables.

I'd expect that complete notification doesn't count as an item and therefore it should ignore the complete notification from the first source Observable and wait until Observable.of(2).delay(500) emits. But it doesn't because of the default behavior of OuterSubscriber at https://github.com/ReactiveX/rxjs/blob/master/src/OuterSubscriber.ts#L20-L22

I checked also RxJS 4 amb operator and it works the same as RxJS 5.4.0 right now. Its description is maybe even more ambiguous when saying:

Propagates the observable sequence or Promise that reacts first

changed the title Observable.race() completes immediately when one of its sources complete Observable.race() completes immediately when one of its sources complete before emitting any item Jun 5, 2017

I know this issue is closed but I faced the exact same issue by relying on the existing documentation. That being said, I think the documentation should be updated to include a mention about completed Observables.

Next I'd like to know what is the preferred way to achieve what the original author wanted to do? Meaning, have n Observable instances, get first value from any of the instancesv whichever has that value available first. Ignore completed Observables.