minor refactoring
This commit is contained in:
parent
d713d5be0a
commit
2c0f88b6f4
|
@ -4,29 +4,29 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Poller struct {
|
type Sampler struct {
|
||||||
consumer Consumer
|
consumer Consumer
|
||||||
item Item
|
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)))
|
ticker := time.NewTicker(time.Duration(rateMs * int(time.Millisecond)))
|
||||||
poller := Poller{consumer, item}
|
sampler := Sampler{consumer, item}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
poller.poll()
|
sampler.sample()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
return poller
|
return sampler
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *Poller) poll() {
|
func (self *Sampler) sample() {
|
||||||
|
|
||||||
value, err := self.item.nextValue()
|
value, err := self.item.nextValue()
|
||||||
|
|
||||||
|
|
2
main.go
2
main.go
|
@ -25,7 +25,7 @@ func main() {
|
||||||
layout.AddComponent(chart, chartConfig.Position, chartConfig.Size, widgets.TypeRunChart)
|
layout.AddComponent(chart, chartConfig.Position, chartConfig.Size, widgets.TypeRunChart)
|
||||||
|
|
||||||
for _, item := range chartConfig.Items {
|
for _, item := range chartConfig.Items {
|
||||||
data.NewPoller(chart, item, chartConfig.RefreshRateMs)
|
data.NewSampler(chart, item, chartConfig.RefreshRateMs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue