https://kotlinlang.org logo
Title
k

Kroppeb

11/05/2019, 3:09 AM
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.
runBlocking {
	fun tt(s: CoroutineScope) = s.launch(start = CoroutineStart.LAZY) { }
	val s = this
	tt(s)
}
o

octylFractal

11/05/2019, 3:24 AM
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

streetsofboston

11/05/2019, 3:29 AM
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

Kroppeb

11/05/2019, 4:43 AM
Mmh, I assumed that “can only finish if all its child-coroutines have finished” meant it called .join() on all its children.
b

bdawg.io

11/05/2019, 6:20 AM
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

Kroppeb

11/05/2019, 11:05 AM
Ok thanks