replace mutex-guarded maps with xsync/v2 maps.

This commit is contained in:
fiatjaf
2023-10-03 08:32:07 -03:00
parent 24d1e3aebd
commit bbe186494e
7 changed files with 33 additions and 52 deletions

View File

@ -50,11 +50,10 @@ func (rl *Relay) Start(host string, port int, started ...chan bool) error {
func (rl *Relay) Shutdown(ctx context.Context) {
rl.httpServer.Shutdown(ctx)
rl.clientsMu.Lock()
defer rl.clientsMu.Unlock()
for conn := range rl.clients {
rl.clients.Range(func(conn *websocket.Conn, _ struct{}) bool {
conn.WriteControl(websocket.CloseMessage, nil, time.Now().Add(time.Second))
conn.Close()
delete(rl.clients, conn)
}
rl.clients.Delete(conn)
return true
})
}