ursus
03/14/2021, 2:13 PMAdam Powell
03/14/2021, 2:26 PM.collect
on the upstream flow? Subscription is about who calls .collect
, not about who cancels it. Using the scope of the first subscriber wouldn't work since you couldn't support structured concurrency correctly that way. Which dispatcher would you use and why? Questions like this are all answered by providing an explicit scope for shared flows to collect on.ursus
03/14/2021, 5:04 PMclass FooRepository {
val foo: Observable<Foo> by lazy {
fooDao.foo()
.refCount()
}
}
Not sure how can this leak. Last subscriber unsubscribes the upstream. This is what I do all over the app (+ replay), to cache last db emitsAdam Powell
03/14/2021, 5:12 PMCoroutineContext
. It's a question of where and how it runs. In effect, with flows there's no such thing as a subscribe
without a subscribeOn
and that's just about the dispatcher, ignoring other CoroutineContext
elements.Adam Powell
03/14/2021, 5:14 PMval GlobalRefcountScope = CoroutineScope(NonCancellable + Dispatchers.Unconfined)
and use that, but flow does make you be explicit if that's what you really want.ursus
03/14/2021, 5:19 PMAdam Powell
03/14/2021, 6:32 PM