review comments fixes

This commit is contained in:
Krzysztof Dryś 2023-11-22 09:15:08 +01:00
parent 01a306ea5b
commit 5a23537181
2 changed files with 9 additions and 9 deletions

View File

@ -5,16 +5,16 @@ import (
)
type Hub struct {
id string
onHubIsHasNoClients func(id string)
clients *sync.Map
id string
onHubHasNoClients func(id string)
clients *sync.Map
}
func NewHub(id string, notifyOnEmpty func(id string)) *Hub {
h := &Hub{
id: id,
clients: &sync.Map{},
onHubIsHasNoClients: notifyOnEmpty,
id: id,
clients: &sync.Map{},
onHubHasNoClients: notifyOnEmpty,
}
return h
}
@ -30,7 +30,7 @@ func (h *Hub) unregisterClient(c *Client) {
}
close(c.send)
if h.isEmpty() {
h.onHubIsHasNoClients(h.id)
h.onHubHasNoClients(h.id)
}
}

View File

@ -31,7 +31,7 @@ func TestRemovingEmptyHub(t *testing.T) {
_, h2 := hp.registerClient(channelID, &websocket.Conn{})
if !h1.isEmpty() {
t.Fatalf("Hub does not report it is empty, even though uit should")
t.Fatalf("Hub does not report it is empty, even though it should")
}
if h1 == h2 {
t.Fatal("Old hub wasn't deleted")
@ -56,7 +56,7 @@ func TestCreateRemoveConcurrently(t *testing.T) {
wg := sync.WaitGroup{}
wg.Add(channelsNo * clientsPerChannel)
for i := 0; i < channelsNo; i++ {
var channelID = fmt.Sprintf("channel-%d", i)
channelID := fmt.Sprintf("channel-%d", i)
go func() {
for j := 0; j < clientsPerChannel; j++ {
c, h := hp.registerClient(channelID, &websocket.Conn{})