From 62fbb1d3566db7c9afea1a929920102d51f1af1e Mon Sep 17 00:00:00 2001 From: Sebastian Mark Date: Fri, 25 Oct 2024 23:15:48 +0200 Subject: [PATCH] feat: add a ticker to manage broadcast timing --- internal/websocket/broadcast.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/websocket/broadcast.go b/internal/websocket/broadcast.go index 02b7f0a..2fd5754 100644 --- a/internal/websocket/broadcast.go +++ b/internal/websocket/broadcast.go @@ -10,6 +10,7 @@ import ( // sends continous messages to all connected WebSocket clients. func SendPermanentBroadCastMessage() { + tick := time.NewTicker(time.Second) for { // Marshal the message into JSON format jsonMessage, err := json.Marshal(shared.Message) @@ -25,6 +26,6 @@ func SendPermanentBroadCastMessage() { // The client is responsible for closing itself on error } } - time.Sleep(time.Second) + <-tick.C } }