Flow/Coroutines question: I'm trying to migrate from RxJava to Flow for Android apps. I often write apps where in some starting point of the app (onCreate or the ViewModel init function for example) I subscribe to a bunch of observables. So, a typical
init
of a view model of mine may look like this:
init {
myObservable
.filter { whatever() }
.map { whatever() }
.subscribe { pushToMySubject() }
myOtherObservable
.filter { whatever() }
.map { whatever() }
.subscribe { pushToMyOtherSubject() }
myThirdObservable
.filter { whatever() }
.map { whatever() }
.subscribe { pushToMyThirdSubject() }
}
But when using flow, we can only call
collect
(which if I'm not mistaken is analagous to
subscribe
in RxJava) from within a coroutine context, which makes sense. But, as far as I can tell, calling
collect
blocks that coroutine context (my terminology might be garbage here) so you can't really have the above setup because we wouldn't execute the last two subscribes until the first observable completes.
So two questions:
1. Is my understanding correct?
2. What's the preferred path to handle this sort of scenario?