1 // This file was automatically generated from channels.md by Knit tool. Do not edit. 2 package kotlinx.coroutines.guide.exampleChannel07 3 4 import kotlinx.coroutines.* 5 import kotlinx.coroutines.channels.* 6 <lambda>null7fun main() = runBlocking { 8 val channel = Channel<String>() 9 launch { sendString(channel, "foo", 200L) } 10 launch { sendString(channel, "BAR!", 500L) } 11 repeat(6) { // receive first six 12 println(channel.receive()) 13 } 14 coroutineContext.cancelChildren() // cancel all children to let main finish 15 } 16 sendStringnull17suspend fun sendString(channel: SendChannel<String>, s: String, time: Long) { 18 while (true) { 19 delay(time) 20 channel.send(s) 21 } 22 } 23