Hey there,
so I have a map channel to store connections
type TCP struct {
listener net.Listener
sockets map[int]chan Connection
}
for {
conn, err := t.listener.Accept()
if err != nil {
slog.Error("server error: ", "err", err)
os.Exit(2)
}
newConn := NewConnection(conn, id)
slog.Info("new conn", "val", newConn)
id++
t.sockets[id] = make(chan Connection, 1)
t.sockets[id] <- newConn
slog.Info("total sockets", "len", len(t.sockets))
go handleConnection(&newConn, t.sockets)
}
``` now deep inside `handleConnection` I have
```go
func newUserJoined(room *shared.MultiplayerRoom, sockets map[int]chan Connection) {
// Finding the user from connections for now due to import cycle.
slog.Info("sockets", "len", sockets)
for _, user := range room.Users {
slog.Info("starting the process to send join notification")
conn := <-sockets[user.Id]
slog.Info("sending new user join to user", "id", user.Id)
slog.Info("conn info", "val", conn)
conn.Write(&shared.TCPCommand[shared.MultiplayerRoom]{
Command: shared.NEW_USER_JOINED,
Data: *room,
})
}
}``` where reading ` conn := <-sockets[user.Id]` just blocks the thread