Replies: 1 comment 1 reply
-
First, I’d like to emphasize that the following reflects my personal opinion. To get straight to the point, if you need a However, I personally don’t think this is the best way to use it. Even if Moreover, adding a In light of these considerations, whether the coroutine uses a However, as I mentioned, if you personally need a coroutine with certain settings, you’re free to create and use it. |
Beta Was this translation helpful? Give feedback.
-
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