feat: improve broadcast loop ticker
- rename tick to ticker for clarity
- change infinite loop to range over ticker channel
- add defer statement to stop the ticker properly
- remove unnecessary channel receive operation
🤖
This commit is contained in:
parent
af5b578cb3
commit
f13bdff03f
1 changed files with 3 additions and 4 deletions
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue