chore: align tickers
Some checks failed
Some checks failed
This commit is contained in:
parent
d92447ad1b
commit
cacdfab155
3 changed files with 5 additions and 12 deletions
|
|
@ -111,8 +111,7 @@ func (conn *Connector) GetScheduleLimit(duration int) (float64, error) {
|
|||
// WatchDog triggers meter values messages if older than timeout.
|
||||
// Must be wrapped in a goroutine.
|
||||
func (conn *Connector) WatchDog(ctx context.Context, timeout time.Duration) {
|
||||
tick := time.NewTicker(2 * time.Second)
|
||||
for {
|
||||
for tick := time.NewTicker(2 * time.Second); ; {
|
||||
conn.mu.Lock()
|
||||
update := conn.clock.Since(conn.meterUpdated) > timeout
|
||||
conn.mu.Unlock()
|
||||
|
|
|
|||
|
|
@ -328,14 +328,11 @@ func (c *Pulsatrix) parseMessage(messageType websocket.MessageType, message []by
|
|||
func (c *Pulsatrix) heartbeat(ctx context.Context) {
|
||||
defer c.wg.Done()
|
||||
|
||||
ticker := time.NewTicker(heartbeatInterval)
|
||||
defer ticker.Stop()
|
||||
|
||||
for {
|
||||
for tick := time.NewTicker(heartbeatInterval); ; {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case <-ticker.C:
|
||||
case <-tick.C:
|
||||
enabled := atomic.LoadInt32(&c.enabled) != 0
|
||||
if err := c.Enable(enabled); err != nil {
|
||||
atomic.AddInt32(&c.consecutiveHeartbeatErrors, 1)
|
||||
|
|
|
|||
|
|
@ -156,12 +156,9 @@ func NewSEMP(ctx context.Context, uri, deviceID string, cache time.Duration) (ap
|
|||
|
||||
// heartbeat ensures that device control updates are sent at least once per minute
|
||||
func (wb *SEMP) heartbeat(ctx context.Context) {
|
||||
ticker := time.NewTicker(time.Second)
|
||||
defer ticker.Stop()
|
||||
|
||||
for {
|
||||
for tick := time.NewTicker(time.Second); ; {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
case <-tick.C:
|
||||
// Check if we need to send an update
|
||||
if time.Since(wb.conn.Updated()) >= time.Minute {
|
||||
if err := wb.conn.SendDeviceControl(wb.deviceID, wb.calcPower(wb.enabled, wb.current, wb.phases)); err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue