Channels Intro Code for chapter 11

Just wonder when I run this code using kotlin and coroutines core 1.4.1

while (!kotlinChannel.isClosedForReceive) {
val fruit = kotlinChannel.receive()
println(fruit)
}

I get a ClosedReceiveChannelException. Based on the docs, it seems the producer hasn’t finished sending all the items before isClosedForReceive became true.

Edit: I read on and saw the issue that issue is already closed. So do we still have a race condition for this use case?

However, if I use isClosedForSend, I do not get an exception. Should I have used this flag instead?