From ddf691af9acdfa36b47c2653dcec0d5ad1920ba9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philip=20Dub=C3=A9?= Date: Thu, 25 Jan 2024 16:15:49 +0000 Subject: [PATCH] HeartbeatRoutine: use explicit ticker (#1157) `time.After(x)` is same as `time.NewTicker(x).C` --- flow/connectors/utils/heartbeat.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/flow/connectors/utils/heartbeat.go b/flow/connectors/utils/heartbeat.go index 2ff8e007de..c12a0dce6f 100644 --- a/flow/connectors/utils/heartbeat.go +++ b/flow/connectors/utils/heartbeat.go @@ -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()) @@ -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) } } }()