ghedeon
01/21/2019, 12:47 PMfun main(){
runBlocking{
foo().consumeEach{ println(it) }
}
}
suspend fun foo(): ReceiveChannel<Int> = coroutineScope {
produce<Int>{
channel.send(42)
channel.close()
}
}marstran
01/21/2019, 12:53 PMfoo which will wait until all child coroutines are completed. However, the produce-coroutine will never complete because it suspends when you send 42 (because it's default capacity is 0).marstran
01/21/2019, 12:53 PMfoo function to this: fun CoroutineScope.foo(): ReceiveChannel<Int> = produce<Int>{
channel.send(42)
channel.close()
}marstran
01/21/2019, 12:54 PMrunBlocking.ghedeon
01/21/2019, 1:06 PMrunBlocking{ produce{} } works, then runBlocking{ coroutineScope{ produce{} } } will work as well, because coroutineScope inherits the parent's scope...gildor
01/21/2019, 1:22 PMghedeon
01/21/2019, 1:32 PMcoroutineScope is suspended and send as well, so they block each other.gildor
01/21/2019, 2:28 PM