You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
491 B

5 years ago
5 years ago
  1. package ws
  2. import (
  3. "sync"
  4. )
  5. type Room struct {
  6. Id string
  7. clients map[string]*Client
  8. rwmux *sync.RWMutex
  9. }
  10. func NewRoom(id string) *Room {
  11. room := new(Room)
  12. room.Id = id
  13. room.clients = make(map[string]*Client, 0)
  14. room.rwmux = new(sync.RWMutex)
  15. return room
  16. }
  17. func (t *Room) Len() int {
  18. t.rwmux.RLock()
  19. defer t.rwmux.RUnlock()
  20. return len(t.clients)
  21. }
  22. func (t *Room) DeleteClient(clientId string) {
  23. t.rwmux.Lock()
  24. defer t.rwmux.Unlock()
  25. delete(t.clients, clientId)
  26. }