📅  最后修改于: 2022-03-11 14:53:32.137000             🧑  作者: Mango
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