Rxjava: flatMap(Observable::from).toList() never completes

Created on 16 Apr 2016  Â·  17Comments  Â·  Source: ReactiveX/RxJava

Hi,

as said in the subject, when using these operators together (like, for example, when filtering elements in the list), onNext events are sent for each item of the list to the toList(), but onCompleted is never sent, and so toList() never emits the list.

Question

Most helpful comment

Call filter and toList inside the flatMap

On Sat, Apr 16, 2016, 5:15 PM Sasa Sekulic [email protected] wrote:

It's a separate subject that gives me just the list, but doesn't complete.

So how could I effectively filter the elements of a list (emitted from a
subject that doesn't complete)?

—
You are receiving this because you commented.

Reply to this email directly or view it on GitHub
https://github.com/ReactiveX/RxJava/issues/3861#issuecomment-210902122

All 17 comments

toList() documents that it requires complete so what do you expect it to do?

Well, shouldn't Observable.from(list) emit all the items and then the onCompleted event at the end?

It does, yes, but flatMap doesn't popagate complete.

You need both the source and the inner Observables of flatMap to complete. What is your source to flatMap?

It's a separate subject that gives me just the list, but doesn't complete.

So how could I effectively filter the elements of a list (emitted from a subject that doesn't complete)?

Call filter and toList inside the flatMap

On Sat, Apr 16, 2016, 5:15 PM Sasa Sekulic [email protected] wrote:

It's a separate subject that gives me just the list, but doesn't complete.

So how could I effectively filter the elements of a list (emitted from a
subject that doesn't complete)?

—
You are receiving this because you commented.

Reply to this email directly or view it on GitHub
https://github.com/ReactiveX/RxJava/issues/3861#issuecomment-210902122

ah, haven't thought about that. :blush: thx!

I'm closing this issue due to inactivity. If you have further input on the issue, don't hesitate to reopen this issue or post a new one.

Observable.interval(10, TimeUnit.SECONDS)
                  .flatMap(along -> anotherCompletedObservable())
                  .flatMap(Observable::from)// how to complete this observable?
                  .doOnNext(item -> doSomething())
                  .toList();
Observable.interval(10, TimeUnit.SECONDS)
                  .flatMap(along -> anotherCompletedObservable()
                                              .flatMap(Observable::from)// will this help?
                                              .doOnNext(item -> doSomething())
                                              .toList());

Hi,

I would have a question regarding this situation. I apply 3 filters to my Observable(inside the ftatMap) and I am doing some calculations in them. Should I set again the subscribeOn(Schedulers.computation()) inside the flatMap ?

Regards,
Gabor

It depends on what source and operators do your function return for flatMap and otherwise where the whole setup runs. If there is a chance it might flatMap on the main thread but you want to make sure the 3 filters run off of the main thread, then you may use subscribeOn/observeOn.

As Jake said: "Call filter and toList inside the flatMap" Is there any other solution to do not call anything inside the flatMap? It looks a bit ugly.

By definition, using and composing standard operators is beautiful :)

So this is a hidden No =))

Very stupid and confusing feature. Have ran into this several times. So the suggestion is to essentially break the chain (or the simplicity of the chain) so the thing actually acts as expected?

What is your suggestion, @breakline87? How should flatMap know you don't intend to have more values to be mapped into Observables?

calling toObservable() after toList() works also. So you can handle the onNext().

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Jaap-van-Hengstum picture Jaap-van-Hengstum  Â·  3Comments

dimsuz picture dimsuz  Â·  4Comments

midnight-wonderer picture midnight-wonderer  Â·  3Comments

archenroot picture archenroot  Â·  3Comments

theblang picture theblang  Â·  3Comments