Skip to content

Commit

Permalink
Replace ticker with timer
Browse files Browse the repository at this point in the history
  • Loading branch information
Pliner committed Feb 18, 2019
1 parent 887c351 commit c9102f7
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions filter/matched_metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,10 @@ func (matcher *MetricsMatcher) receiveBatch(metrics <-chan *moira.MatchedMetric)

go func() {
defer close(batchedMetrics)

batchTicker := time.NewTicker(time.Second)
defer batchTicker.Stop()

batchTimer := time.NewTimer(time.Second)
defer batchTimer.Stop()
for {
batch := make(map[string]*moira.MatchedMetric)

retry:
select {
case metric, ok := <-metrics:
Expand All @@ -71,12 +68,12 @@ func (matcher *MetricsMatcher) receiveBatch(metrics <-chan *moira.MatchedMetric)
goto retry
}
batchedMetrics <- batch
case <-batchTicker.C:
case <-batchTimer.C:
batchedMetrics <- batch
}
batchTimer.Reset(time.Second)
}
}()

return batchedMetrics
}

Expand Down

0 comments on commit c9102f7

Please sign in to comment.