Uli Bubenheimer
06/07/2024, 7:22 PMZach Klippenstein (he/him) [MOD]
06/07/2024, 11:26 PMUli Bubenheimer
06/07/2024, 11:42 PMUli Bubenheimer
06/08/2024, 12:30 AMcoroutineScope {
val job1 = launch(<http://Dispatchers.IO|Dispatchers.IO>) {
// bad job: runs for a long time, and fails to suspend
while (true) {}
}
launch {
// check that job1 completes soon after parent cancellation
try {
awaitCancellation()
} finally {
GlobalScope.launch {
delay(5.seconds)
if (!job1.isCompleted) println("Not completing")
}
}
}
// Wait a bit, then cancel our parent scope
delay(5.seconds)
this.cancel()
}
Uli Bubenheimer
06/08/2024, 12:47 AMcancelAndJoin()
does not help, because in general there are many ways that job1 could end up getting cancelled.Uli Bubenheimer
06/08/2024, 12:47 AM