Carrascado
08/26/2020, 6:43 PMproduce ? I don't want to avoid produce, it's just for curiosityoctylFractal
08/26/2020, 6:44 PMCoroutineScopeCarrascado
08/26/2020, 6:45 PMoctylFractal
08/26/2020, 6:46 PMCarrascado
08/26/2020, 6:46 PMAndrea Giuliano
08/26/2020, 6:47 PMoctylFractal
08/26/2020, 6:48 PMproduceAndrea Giuliano
08/26/2020, 6:48 PMoctylFractal
08/26/2020, 6:49 PMfun CoroutineScope.produceSquares(): ReceiveChannel<Int> {
val channel = Channel<Int>()
launch {
for (x in 1..5) channel.send(x * x)
channel.close()
}
return channel
}octylFractal
08/26/2020, 6:49 PMproduce gives youCarrascado
08/26/2020, 6:51 PMCarrascado
08/26/2020, 6:51 PMAndrea Giuliano
08/26/2020, 7:04 PMsuspend fun produceSquares(): ReceiveChannel<Int> = coroutineScope {
produce {
for (x in 1..5) {
send(x * x)
}
}
}
so in practice you are not making produceSquare an extension function for CoroutineScope the code blocks after sending the first item in the channel. As if in the original example the channel gets created with the right side while in this snippet it gets created with 0 capacity?
Anyone knows why?octylFractal
08/26/2020, 7:05 PMcoroutineScope works, right? it suspends until all child coroutines complete, which includes produceAndrea Giuliano
08/26/2020, 7:05 PMAndrea Giuliano
08/26/2020, 7:07 PMoctylFractal
08/26/2020, 7:09 PMAndrea Giuliano
08/26/2020, 7:09 PM