GoTomato/internal/websocket/staleClients.go

23 lines
358 B
Go
Raw Normal View History

package websocket
import (
"time"
)
// Check and remove stale clients
func RemoveStaleClients() {
ticker := time.NewTicker(30 * time.Second)
defer ticker.Stop()
for range ticker.C {
mu.Lock()
for _, client := range Clients {
if client.IsStale() {
client.Conn.Close()
2024-11-20 21:01:56 +00:00
delete(Clients, client.Conn.LocalAddr())
}
}
mu.Unlock()
}
}