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
I'm exploring the differences between AAC ViewModel's viewModelScope and Compose's rememberCoroutineScope, particularly in the context of using Circuit.
I understand that when using Circuit, since we use Circuit Presenter instead of AAC ViewModel, we're supposed to use rememberCoroutineScope or rememberStableCoroutineScope to replace viewModelScope
The key difference is that viewModelScope creates a coroutine scope with a SupervisorJob, which ensures that exceptions or cancellations in child coroutines don't affect other coroutines. This is an important design choice for error handling.
In contrast, rememberCoroutineScope (and rememberStableCoroutineScope) in Circuit Presenter seems to only provide automatic cancellation tied to the Composable's lifecycle:
If we want viewModelScope-like stability in Circuit, we might need to consider explicitly using SupervisorJob when creating coroutine scopes. However, I'd like to learn more about this before making a final decision.
Questions:
Is this understanding of the differences between viewModelScope and rememberCoroutineScope correct?
What would be the recommended way to achieve viewModelScope-like error handling in Circuit?
Would combining rememberCoroutineScope with SupervisorJob actually solve the concerns mentioned above?
Looking forward to community insights and discussions on this topic.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm exploring the differences between AAC ViewModel's viewModelScope and Compose's rememberCoroutineScope, particularly in the context of using Circuit.
I understand that when using Circuit, since we use Circuit Presenter instead of AAC ViewModel, we're supposed to use rememberCoroutineScope or rememberStableCoroutineScope to replace viewModelScope
OrderServicesPresenter.kt in CatchUp
The viewModelScope in AAC ViewModel provides more than just a coroutine scope that terminates with the ViewModel's lifecycle:
The key difference is that viewModelScope creates a coroutine scope with a
SupervisorJob
, which ensures that exceptions or cancellations in child coroutines don't affect other coroutines. This is an important design choice for error handling.In contrast,
rememberCoroutineScope
(andrememberStableCoroutineScope
) in Circuit Presenter seems to only provide automatic cancellation tied to the Composable's lifecycle:If we want viewModelScope-like stability in Circuit, we might need to consider explicitly using SupervisorJob when creating coroutine scopes. However, I'd like to learn more about this before making a final decision.
Questions:
Is this understanding of the differences between viewModelScope and rememberCoroutineScope correct?
What would be the recommended way to achieve viewModelScope-like error handling in Circuit?
Would combining rememberCoroutineScope with SupervisorJob actually solve the concerns mentioned above?
Looking forward to community insights and discussions on this topic.
Beta Was this translation helpful? Give feedback.
All reactions