Skip to content

Commit

Permalink
HeartbeatRoutine: use explicit ticker (#1157)
Browse files Browse the repository at this point in the history
`time.After(x)` is same as `time.NewTicker(x).C`
  • Loading branch information
serprex authored Jan 25, 2024
1 parent 94cb719 commit ddf691a
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion flow/connectors/utils/heartbeat.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ func HeartbeatRoutine(
shutdown := make(chan struct{})
go func() {
counter := 0
ticker := time.NewTicker(15 * time.Second)
defer ticker.Stop()

for {
counter += 1
msg := fmt.Sprintf("heartbeat #%d: %s", counter, message())
Expand All @@ -25,7 +28,8 @@ func HeartbeatRoutine(
return
case <-ctx.Done():
return
case <-time.After(15 * time.Second):
case <-ticker.C:
ticker.Reset(15 * time.Second)
}
}
}()
Expand Down

0 comments on commit ddf691a

Please sign in to comment.