diff --git a/bandwidth.go b/bandwidth.go index 39c9f1b..15e0083 100644 --- a/bandwidth.go +++ b/bandwidth.go @@ -73,6 +73,8 @@ outer: } close(bw.AddRx) close(bw.AddTx) + close(bw.Rx) + close(bw.Tx) } // datum stores both a piece of info, plus the time at which that info was @@ -116,6 +118,16 @@ func newStream(seconds []int) *stream { func (s *stream) add(v datum) { s.data.PushBack(v) +} + +func (s *stream) averages() []float64 { + var limit time.Time + total := 0.0 + totals := []float64{} + + if s.data.Back() == nil { + return totals + } newest := s.data.Back().Value.(datum) cutoff := newest.at.Add(s.max) for e := s.data.Front(); e != nil; e = e.Next() { @@ -126,19 +138,7 @@ func (s *stream) add(v datum) { break } } -} -func (s *stream) averages() []float64 { - var limit time.Time - - total := 0.0 - - totals := []float64{} - if s.data.Back() == nil { - return totals - } - - newest := s.data.Back().Value.(datum) e := s.data.Back() for _, extent := range s.extents {