📜  kotlin 协程通道 - Kotlin 代码示例

📅  最后修改于: 2022-03-11 14:53:32.137000             🧑  作者: Mango

代码示例1
Channels
fun CoroutineScope.produceSquares():
 ReceiveChannel = produce {
 for (x in 1..5) send(x * x)
 }
val squares = produceSquares()
repeat(5) { println(squares.receive()) } // 1, 4, 9, 16, 25
val squares2 = produceSquares()
for(square in squares2) print(square) // 1, 4, 9, 16, 25