The follow code will never end, and if forcefully ...
# coroutines
k
The follow code will never end, and if forcefully stopped the dump lists no coroutines. I have a workaround but I was wondering if this is a bug or just how it's supposed to be? It feels counterintuitive.
Copy code
runBlocking {
	fun tt(s: CoroutineScope) = s.launch(start = CoroutineStart.LAZY) { }
	val s = this
	tt(s)
}
o
well, if you never start the job, it won't ever finish, so runBlocking can't return. seems logical to me
đź‘Ť 1
I don't recall how the dump works, but I think it only reports active coroutines, which an unstarted one isn't yet. the job is attached to the parent, but the coroutine hasn't begun execution
s
A
CoroutineScope
can only finish if all its child-Coroutines have finished (Structured Concurrency). The CoroutineScope provided by the runBlocking never ends/finishes since one of its child-Coroutines (s.launch) never finishes. Therefore the call to runBlocking never returns, since it only will return after its CoroutineScope ends.
k
Mmh, I assumed that “can only finish if all its child-coroutines have finished” meant it called .join() on all its children.
b
It's effectively the same thing except it doesn't manipulate the life-cycle of the children (so it won't start jobs that are still new, but not started)
k
Ok thanks