Skip to content

Commit cacdfab

Browse files
committed
chore: align tickers
1 parent d92447a commit cacdfab

File tree

3 files changed

+5
-12
lines changed

3 files changed

+5
-12
lines changed

charger/ocpp/connector.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,7 @@ func (conn *Connector) GetScheduleLimit(duration int) (float64, error) {
111111
// WatchDog triggers meter values messages if older than timeout.
112112
// Must be wrapped in a goroutine.
113113
func (conn *Connector) WatchDog(ctx context.Context, timeout time.Duration) {
114-
tick := time.NewTicker(2 * time.Second)
115-
for {
114+
for tick := time.NewTicker(2 * time.Second); ; {
116115
conn.mu.Lock()
117116
update := conn.clock.Since(conn.meterUpdated) > timeout
118117
conn.mu.Unlock()

charger/pulsatrix.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -328,14 +328,11 @@ func (c *Pulsatrix) parseMessage(messageType websocket.MessageType, message []by
328328
func (c *Pulsatrix) heartbeat(ctx context.Context) {
329329
defer c.wg.Done()
330330

331-
ticker := time.NewTicker(heartbeatInterval)
332-
defer ticker.Stop()
333-
334-
for {
331+
for tick := time.NewTicker(heartbeatInterval); ; {
335332
select {
336333
case <-ctx.Done():
337334
return
338-
case <-ticker.C:
335+
case <-tick.C:
339336
enabled := atomic.LoadInt32(&c.enabled) != 0
340337
if err := c.Enable(enabled); err != nil {
341338
atomic.AddInt32(&c.consecutiveHeartbeatErrors, 1)

charger/semp.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,9 @@ func NewSEMP(ctx context.Context, uri, deviceID string, cache time.Duration) (ap
156156

157157
// heartbeat ensures that device control updates are sent at least once per minute
158158
func (wb *SEMP) heartbeat(ctx context.Context) {
159-
ticker := time.NewTicker(time.Second)
160-
defer ticker.Stop()
161-
162-
for {
159+
for tick := time.NewTicker(time.Second); ; {
163160
select {
164-
case <-ticker.C:
161+
case <-tick.C:
165162
// Check if we need to send an update
166163
if time.Since(wb.conn.Updated()) >= time.Minute {
167164
if err := wb.conn.SendDeviceControl(wb.deviceID, wb.calcPower(wb.enabled, wb.current, wb.phases)); err != nil {

0 commit comments

Comments
 (0)