Answers for "kotlin coroutine channel"

0

kotlin coroutine channel

Channels
fun CoroutineScope.produceSquares():
 ReceiveChannel<Int> = 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
Posted by: Guest on January-15-2021

Browse Popular Code Answers by Language