Hi!
If I create an observable using Observable.create() and I don鈥檛 call onCompleted on its subscriber, following chaining operation toList() does not get executed.
private Observable<List<String>> createObservable() {
return Observable.create(subscriber -> {
subscriber.onNext("");
subscriber.onCompleted(); //if onCompleted is not called the operations chained after calling flatMapIterable() -> toList() do not execute
})
.map(string -> Arrays.asList("1", "2", "3"));
}
createObservable()
.flatMapIterable(strings -> strings)
.map(string -> string)
.toList()
.map(strings -> strings); //this line is not executed if the source observable does not call onCompleted()
Is this the expected behaviour?
Thanks!
Yes. toList gives you the complete list of all values, but it has to know when there are no more values. Without onCompleted() it can't know you forgot it or it got just delayed a bit.
Thanks!
Most helpful comment
Yes.
toListgives you the complete list of all values, but it has to know when there are no more values. WithoutonCompleted()it can't know you forgot it or it got just delayed a bit.