I have the following code:
suspend fun main() {
val c = Channel<Int>()
coroutineScope {
launch {
c.send(2)
println("never printed")
}
delay(300)
c.close()
println("closed")
}
println("end")
}
This program hung indefinetly in the send(2)
instruction.
Changing it to receive()
instead throws an exception upon closing the channel.
Is there a way to have send()
behaving like receive()
when closing the channel?