ursus
10/24/2020, 9:35 PMgildor
10/25/2020, 3:36 AMIf I were to have scope as param that would not be nice api.No, it’s very nice API, it force you to think on lifecycle of this thing, with RxJava you just do not care and may easily leak
semantically its not GlobalScope since FooRepository say only lives during user being logged inSo you answered your own question, provide UserScope, which created on login and cancelled on logout
ursus
10/25/2020, 1:38 PMgildor
10/25/2020, 2:18 PMursus
10/25/2020, 2:27 PMobject FooRepository {
val foos: Flow<List<Foo>> = flow { emit(readFoos()) }.shareIn(scope = GlobalScope, started = SharingStarted.Lazily())
}
Activity1 {
scope.launch {
FooRepository.foos
.collect {
Log.d("Default", "activity1=$it")
}
}
}
Activity2 {
scope.launch {
FooRepository.foos
.collect {
Log.d("Default", "activity2=$it")
}
}
}
Activity 1 initiates readFoo and gets result, then via a button I move to Activity2 and that doesnt receive the cached result, nor initiates readFoos -- I must be doing something wrong (If I remove the shareIn and place it in a getter then it works as expected, but obviously without the caching, so the callsites I think are okay) i.e. using the shareIn wronglygildor
10/25/2020, 2:29 PMursus
10/25/2020, 2:31 PMgildor
10/25/2020, 2:31 PMursus
10/25/2020, 2:31 PMgildor
10/25/2020, 2:32 PMursus
10/25/2020, 2:33 PM