📅  最后修改于: 2022-03-11 15:00:50.154000             🧑  作者: 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