필요하지 않은 Coroutine을 적절히 취소해 Computing 자원을 아껴야한다!!

fun main(): Unit = runBlocking {
    val job = launch {
        var i = 1
        var nextPrintTime = System.currentTimeMillis()
        while (i <= 5) {
            if (System.currentTimeMillis() >= nextPrintTime) {
                printWithThread("Hello $i")
                nextPrintTime += 1_000L
                i++
            }
        }
    }

    delay(100L)
    job.cancel()
}
fun main(): Unit = runBlocking {
    val job = launch(Dispatchers.Default) {
        var i = 1
        var nextPrintTime = System.currentTimeMillis()
        while (i <= 5) {
            if (System.currentTimeMillis() >= nextPrintTime) {
                printWithThread("Hello $i")
                nextPrintTime += 1_000L
                i++
            }

            if (!isActive) {
                throw CancellationException()
            }
        }
    }

    delay(100L)
    job.cancel()
}