feat: remove unused client mutex
- remove unused Mutex from `models.Client` struct
- remove lock from `HandleConnection()`
- replace websocket.Conn with models.Client in `handleClientCommands()`
🤖
This commit is contained in:
parent
94b6786c7c
commit
bdfd5c3b84
3 changed files with 8 additions and 12 deletions
|
@ -3,7 +3,6 @@ package models
|
|||
import (
|
||||
"github.com/charmbracelet/log"
|
||||
"github.com/gorilla/websocket"
|
||||
"sync"
|
||||
)
|
||||
|
||||
// Represents a command from the client (start/stop)
|
||||
|
@ -15,16 +14,12 @@ type ClientCommand struct {
|
|||
|
||||
// Represents a single client
|
||||
type Client struct {
|
||||
Conn *websocket.Conn // Websocket connection of the client
|
||||
Mutex sync.Mutex // Mutex used to lock
|
||||
Conn *websocket.Conn
|
||||
}
|
||||
|
||||
// Sends a message to the websocket.
|
||||
// Automatically locks and unlocks the client mutex, to ensure that only one goroutine can write at a time.
|
||||
func (c *Client) SendMessage(messageType int, data []byte) error {
|
||||
c.Mutex.Lock()
|
||||
defer c.Mutex.Unlock()
|
||||
|
||||
err := c.Conn.WriteMessage(messageType, data)
|
||||
if err != nil {
|
||||
log.Error("Error writing to WebSocket:", "msg", err)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue