in UI composable. Now, when i background the app, will the coroutine launched by molecule still be active?
s
Stylianos Gakis
06/17/2024, 7:47 AM
This doesn't have something to do with Molecule itself, your flow will ve paused if you give it information on when it will be paused using stateIn(SharingStarted.WhileSubscribed(seconds here)).
So it all depends on how you create your StateFlow
Otherwise it will keep being alive
yes black 1
s
Sam
06/23/2024, 10:22 PM
@Stylianos Gakis stateIn works only when dealing with upstream cold flows. The flow from
launchMolecule
is a hot one. Updated using
moleculeFlow
and that did it. Thanks.
s
Stylianos Gakis
06/24/2024, 10:35 AM
Yeap, hence I said "it all depends on how you create your StateFlow". Creating it with stateIn is the only way, if you've created another StateFlow with launchMolecule then that would not be what I suggested 😅
s
Sam
06/25/2024, 1:57 AM
Got it, besides, is there any reason to use
launchMolecule
in Android, given lifecycle scoped observing logic in UI?
s
Stylianos Gakis
06/25/2024, 7:50 AM
I haven't found a use of it myself, but we use AACVM and put our molecule presenters scoped to that so we always have to be careful with that.
Perhaps in some other type of architecture it would make sense? Not sure
s
Sam
06/27/2024, 1:16 AM
Okay, the other case i can think of is when the upstream flows aren't frequently updated or expensive and effectively becomes a no-op when app is backgrounded.
s
Stylianos Gakis
06/27/2024, 9:23 AM
Yes, however I wouldn't rely on this myself.
It's possible for a previously "cheap" flow to get another source of data which is quite expensive, and have this change happen in the data layer without any API changes and whatnot. In those scenarios you wouldn't want to have to go and check the call sites one by one to make sure nobody assumes that this was a cheap flow and needs changing.
It's best to just do the right thing always and then you are free to make such changes without having to change unrelated code at the same time.