️ WS 通信阻塞读写锁

This commit is contained in:
naiba
2022-03-13 10:44:30 +08:00
parent d60bc3dad6
commit d928f65052
3 changed files with 6 additions and 4 deletions

View File

@@ -140,14 +140,16 @@ func (cp *commonPage) ws(c *gin.Context) {
return
}
defer conn.Close()
var servers []*model.Server
count := 0
for {
singleton.SortedServerLock.RLock()
servers = singleton.SortedServerList
singleton.SortedServerLock.RUnlock()
err = conn.WriteJSON(Data{
Now: time.Now().Unix() * 1000,
Servers: singleton.SortedServerList,
Servers: servers,
})
singleton.SortedServerLock.RUnlock()
if err != nil {
break
}