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

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.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 17 (8 by maintainers)

Most upvoted comments

Call filter and toList inside the flatMap

On Sat, Apr 16, 2016, 5:15 PM Sasa Sekulic notifications@github.com 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

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());

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.

ah, haven’t thought about that. 😊 thx!