Skip to content

Can rememberCoroutineScope and rememberStableCoroutineScope really replace viewModelScope in Circuit? #1883

Answered by vulpeszerda
easyhooon asked this question in Q&A
Discussion options

You must be logged in to vote

First, I’d like to emphasize that the following reflects my personal opinion.

To get straight to the point, if you need a CoroutineScope configured with a SupervisorJob, you can create it in the same way rememberCoroutineScope does.

However, I personally don’t think this is the best way to use it.

Even if viewModelScope is created with a SupervisorJob, if you don’t explicitly specify a CoroutineExceptionHandler, any unhandled exception thrown by a coroutine in the viewModelScope will trigger Thread.uncaughtExceptionHandler, which will crash the app.

Moreover, adding a CoroutineExceptionHandler when launching a coroutine can lead to mistakes, as seen in this case. Therefore, for coroutine …

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@easyhooon
Comment options

Answer selected by easyhooon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants