title: How to test if a channel is close and only send to it when it's not closed
body: <p>In Go, if a channel <code>channel</code> is closed, I can still read from it using the following syntax and I can test <code>ok</code> to see if it's closed. </p>
  
  <pre><code>value, ok := &lt;- channel
  if !ok {
      // channel was closed and drained
  }
  </code></pre>
  
  <p>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.</p>