sitepodmatt
03/06/2019, 9:24 AMobject CoroutineCrashTest {
private val scope = GlobalScope + Job()
fun run() = scope.launch(Dispatchers.Default) {
doAwaitInside()
}
private suspend fun doAwaitInside() {
supervisorScope {
try {
testAsync().await()
} catch (e: IllegalStateException) {
// catched but still crash
}
}
}
private fun testAsync() = scope.async(Dispatchers.Default) {
throw IllegalStateException("test")
}
}
Landerl Young
03/06/2019, 9:27 AMGlobalScope + Job
(the default CoroutineScope() method always add a job) to GlobalScope
, the crash goes away?private suspend fun testAsync() =
supervisorScope {
async(Dispatchers.Default) {
throw IllegalStateException("test")
}
}
louiscad
03/06/2019, 9:34 PMcoroutineScope { … }
that encloses async
calls. No need for supervisorScope
here. Search for "local scope" in this Slack, you'll see examples if you need them, this has already been covered numerous times.async
the way you showed in this thread is pointless and defeats the purpose async, showing you don't need async
at all.Landerl Young
03/07/2019, 2:50 AM