Skip to content

Commit

Permalink
Follow rate limit more closely by including update execution time (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
andig authored Apr 10, 2020
1 parent 835d0dc commit 851ad89
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions meters/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ type DeviceDescriptor struct {

// Device is a modbus device that can be described, probed and queried
type Device interface {
// Initialize prepares the device for usage. Any setup or initilization should be done here.
// Initialize prepares the device for usage. Any setup or initialization should be done here.
// It requires that the client has the correct device id applied.
Initialize(client modbus.Client) error

// Descriptor returns the device descriptor. Since this method does not have
// bus access the descriptor should be preared during initilization.
// bus access the descriptor should be prepared during initialization.
Descriptor() DeviceDescriptor

// Probe tests if a basic register, typically VoltageL1, can be read.
Expand Down
5 changes: 4 additions & 1 deletion server/queryengine.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ func (q *QueryEngine) Run(
for _, h := range q.handlers {
wg.Add(1)
go func(h *Handler) {
ticker := time.NewTicker(rate)
defer ticker.Stop()

for {
// run handlers
h.Run(ctx, control, results)
Expand All @@ -95,7 +98,7 @@ func (q *QueryEngine) Run(
// abort if context is cancelled
wg.Done()
return
case <-time.After(rate):
case <-ticker.C:
}
}
}(h)
Expand Down

0 comments on commit 851ad89

Please sign in to comment.