diff --git a/internal/websocket/broadcast.go b/internal/websocket/broadcast.go index 57f4449..e2c175d 100644 --- a/internal/websocket/broadcast.go +++ b/internal/websocket/broadcast.go @@ -11,9 +11,10 @@ import ( // Sends continous messages to all connected WebSocket clients func SendPermanentBroadCastMessage() { - tick := time.NewTicker(time.Second) + ticker := time.NewTicker(time.Second) + defer ticker.Stop() - for { + for range ticker.C { // Marshal the message into JSON format jsonMessage, err := json.Marshal(shared.State) if err != nil { @@ -32,7 +33,5 @@ func SendPermanentBroadCastMessage() { } } mu.Unlock() - - <-tick.C } }