You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Wrap subscription action with lifecycle whenStarted (#665)
* Wrap subscription action with lifecycle `whenStarted`
The specifics of behaviour of `flowWhenStarted` implementation implicitly used in resolve subscription will allow submitted action to resume continuation even if lifecycle is moved into stopped state. For example:
```
// Fragment
override fun onCreate(savedInstanceState: Bundle?) {
viewModel.onEach(ViewState::isVisible) { isVisible ->
...
binding.someview.reveal() // (1) suspendable, performs animation
binding.someview.text = "" // (2) touches other UI after continuation
...
}
}
```
Users can observe crash in above example if lifecycle of view moved into stopped state while coroutine was suspended at (1) suspension point. The reason is that submitted action via `onEach` won't be paused / canceled when reached suspension point and lifecycle moved into stopped state (see implementations of `collectLatest` and `flowWhenStarted` together).
The recommendation was to wrap submitted `onEach` action into `whenStarted` on the user side to make coroutine paused when lifecycle is stopped.
But why not change this on mavericks side and address this issue at the core?
0 commit comments