Using a buffered channel, how do measure how many elements are in the channel? For example, I'm creating and sending on a channel like this:
send_ch := make(chan []byte, 100)
// code
send_ch <- msg
I want to measure how many msgs are in the channel send_ch.
I'm aware that due to concurrency the measurement won't be exact, as pre-emption could occur between measurement and action (eg discussed in this video Google I/O 2012 - Go Concurrency Patterns). I'll be using this for flow control between producers and consumers ie once I've passed through a high watermark, changing some behaviour until I pass back through a low watermark.