In Go, if a channel channel
is closed, I can still read from it using the following syntax and I can test ok
to see if it's closed.
value, ok := <- channel
if !ok {
// channel was closed and drained
}
However, if I don't know whether a channel is closed and blindly write to it, I may got an error. I want to know if there is any way that I can test the channel and only write to it when it's not closed. I ask this question is because sometimes I don't know if a channel is closed or not in a goroutine.