Skip to content

Commit

Permalink
fix: publish stats to all client in interval to reduce load
Browse files Browse the repository at this point in the history
  • Loading branch information
client-side96 committed May 30, 2024
1 parent 3834f01 commit 18fdda3
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions cmd/pi-monitor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,28 @@ var scriptDir string
var addr string

func mainLoop(statsService *service.StatsService) {

ticker := time.NewTicker(1 * time.Second)
done := make(chan bool)

defer func() {
ticker.Stop()
done <- true
}()

for {
select {
case <-done:
return
case <-ticker.C:
statsService.PublishToAllClients()
case client := <-statsService.Channel:
statsService.HandleStatsSubscripition(client)
default:
statsService.PublishToAllClients()
// default:

}
}

}

func main() {
Expand Down

0 comments on commit 18fdda3

Please sign in to comment.