Endre Deak
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.cancelChildren import kotlinx.coroutines.delay import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import sun.misc.Signal suspend fun main() { withContext(Dispatchers.Default) { Signal.handle(Signal("INT")) {signal -> println("RECEIVED ${signal.name}") this.coroutineContext.cancelChildren() } launch { withContext(Dispatchers.Default) { launch { while (true) { try { println("foo") // delay(2000) // if I put delay here, it fails with an infinite loop on SIGINT } catch (e: Exception) { println("error: ${e.message}") } delay(2000) // if I put delay here outside try-catch, no problem on SIGINT } } } } } println("finished") }
delay
try-catch
ephemient
CancellationException
A modern programming language that makes developers happier.