Joel Steres
11/11/2022, 6:01 PMobserveLoginState().map { it is LoggedIn }
.distinctUntilChanged()
.flatMapLatest { isLoggedIn ->
if (isLoggedIn) { dataSource.observe() }
else { emptyFlow() }
}
...
.flatMap {}
,,,
,launchedIn(scope)
However it really seems like the downstream flatMaps are continuing to observe even when a flatMapLatest upstream has changed. Am I doing something wrong? Is there a way to cancel the downstream observers while keeping the flow alive?
A couple of other ideas I tried:
• Threading a null or sentinel value through the flow so downstream observers could be swapped out but requires too many compromises about the type of data based along the flow.
• throwing an exception and using retryWhen to restart the flow. I ran into an exception retry loop when logged out which I should have seen even before I tried. Even though I expect it could be made workable, I didn’t really spend the time looking further as it felt kludgey.brandonmcansh
11/15/2022, 3:19 PMbrandonmcansh
11/15/2022, 3:20 PM