Don't close throttle channel, explain why

This commit is contained in:
Ethan Frey 2017-12-06 22:28:18 +01:00
parent e430d3f844
commit 8b518fadb2
2 changed files with 4 additions and 1 deletions

View File

@ -52,8 +52,8 @@ func (t *ThrottleTimer) run() {
select {
case cmd := <-t.input:
// stop goroutine if the input says so
// don't close channels, as closed channels mess up select reads
if t.processInput(cmd) {
close(t.Ch)
return
}
case <-t.timer.C:

View File

@ -31,6 +31,9 @@ func (c *thCounter) Count() int {
// Read should run in a go-routine and
// updates count by one every time a packet comes in
func (c *thCounter) Read() {
// note, since this channel never closes, this will never end
// if thCounter was used in anything beyond trivial test cases.
// it would have to be smarter.
for range c.input {
c.Increment()
}