Guru
06/08/2019, 7:59 AMval job = runBlocking {
val channel: Channel<Int> = Channel()
launch(CoroutineName("PRODUCER")) {
for (item in 1..100) {
channel.send(item)
println("PRODUCED: $item")
delay(10)
if (item == 50) delay(1000)
}
todo {
//TODO
channel.close()
}
println("PRODUCER - DONE")
}
launch(CoroutineName("CONSUMER")) {
while (!channel.isClosedForSend) {
println("LOOP BEGIN")
for (item in channel) {
println("RECIEVED: $item")
}
}
println("ALL DONE")
}
}