Observable.race() completes immediately when one of its sources complete before emitting any item
· 4 comments
.subscribe(console.log, null, () => console.log('complete'));
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 Observable
s.
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.