Julia Samól
08/25/2023, 9:33 AMnewSingleThreadContext("MyName").use {
runBlocking(it) {
// some suspend calls, including `delay`
}
}
but it always ended up with the ANR error. Is that expected? I thought that runBlocking
blocked the current thread, which in this case should be a new background thread, not the main thread. If that’s the case, then why this code would result in ANR?
Slack ConversationSam
08/25/2023, 10:20 AMrunBlocking
always blocks the current thread, while it waits for its child coroutines to complete. The context you pass in can change which thread the coroutines are running on, but it doesn't change which thread is waiting for them. If you don't want the current thread to wait for the coroutines to complete, maybe you want to make a coroutine scope with your new context and use launch
instead of runBlocking
.Julia Samól
08/28/2023, 7:16 AMrunBlocking
also runs on the new thread, but now it all makes sense 😅 thanks!