Is there anything like 'daemon coroutine' in `coro...
# coroutines
l
Is there anything like 'daemon coroutine' in
coroutineScope
that will be cancelled if other things in it are completed? Normally tasks running in
launch
in it will cause
coroutineScope
not to return.
e
one possibility:
Copy code
runBlocking {
    val job = Job()
    launch(job) {
        while (true) yield()
    }
    launch(job) {
        delay(5_000)
    }

    delay(100)

    job.cancel()
}
// done in 100ms
l
I asked this because I was lazy to write `.cancel()`; However this seems quite good.
Maybe I could use simple try .. finally...
e
you shouldn't need try-finally, an exceptional coroutine termination automatically cancels children