minor refactoring

This commit is contained in:
sqshq 2019-02-02 23:11:26 -05:00
parent d713d5be0a
commit 2c0f88b6f4
2 changed files with 7 additions and 7 deletions

View File

@ -4,29 +4,29 @@ import (
"time"
)
type Poller struct {
type Sampler struct {
consumer Consumer
item Item
}
func NewPoller(consumer Consumer, item Item, rateMs int) Poller {
func NewSampler(consumer Consumer, item Item, rateMs int) Sampler {
ticker := time.NewTicker(time.Duration(rateMs * int(time.Millisecond)))
poller := Poller{consumer, item}
sampler := Sampler{consumer, item}
go func() {
for {
select {
case <-ticker.C:
poller.poll()
sampler.sample()
}
}
}()
return poller
return sampler
}
func (self *Poller) poll() {
func (self *Sampler) sample() {
value, err := self.item.nextValue()

View File

@ -25,7 +25,7 @@ func main() {
layout.AddComponent(chart, chartConfig.Position, chartConfig.Size, widgets.TypeRunChart)
for _, item := range chartConfig.Items {
data.NewPoller(chart, item, chartConfig.RefreshRateMs)
data.NewSampler(chart, item, chartConfig.RefreshRateMs)
}
}