1

How can I collect emitted items from observable to List when observable never completes?

Example I have something similar so Observable emits series of values, but never completes unless you unsubscribe, because of that .toList() not gonna work.

Observable<User>
 .flatMap {}
 .toList()

How can I collect All users to List and emit it once after applying flatMap function to it?

LeTadas
  • 3,436
  • 9
  • 33
  • 65
  • Read here: https://github.com/ReactiveX/RxJava/wiki/Blocking-Observable-Operators – ryanafrish7 Jun 12 '19 at 19:45
  • What are the conditions? I mean, when do you know you should emit the list of all users if the observer never completes? – Fred Jun 14 '19 at 14:08

1 Answers1

2

There are a few options here. If you want to collect them periodically you could use buffer(). Or if you have some other signal to collect you might use where().

jbarat
  • 2,382
  • 21
  • 23