RxJava / RxJs: How to merge two source observables but complete as soon as one of them completes
You need to work with the metadata, information about each observable. To do this, use the materialize()
operator on each stream and the use dematerialize()
on the merged stream to actually emit the data.
Observable.merge( observableA.materialize(),
observableB.materialize() )
.takeWhile( notification -> notification.hasValue() )
.dematerialize()
.subscribe( ... );
This will merge the two observables until either one of them completes or emits an error.