Rxjava: Why does affect not calling subsciber.onCompleted() when applying operator observable.toList()?

Created on 17 Mar 2016  路  2Comments  路  Source: ReactiveX/RxJava

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!

Question

Most helpful comment

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.

All 2 comments

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!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ZakTaccardi picture ZakTaccardi  路  3Comments

midnight-wonderer picture midnight-wonderer  路  3Comments

perlow picture perlow  路  3Comments

francorolando picture francorolando  路  3Comments

Jaap-van-Hengstum picture Jaap-van-Hengstum  路  3Comments