In the following scenario:
runBlocking(Dispatchers.IO) {
val channel = Channel<String>()
launch {
channel.send("Hello World")
channel.close()
}
println(channel.recive())
}
Is it guaranteed that it always prints “Hello World”? In other words, is it possible that channel was closed before “channel.receive()” is called?
Is the answer the same for this case:
runBlocking(Dispatchers.IO) {
val channel = Channel<String>()
launch {
println(channel.recive())
}
launch {
channel.send("Hello World")
channel.close()
}
}
?
Cheers, Jacek.