muxed socket.send fixes #27

This commit is contained in:
Craig 2020-02-03 14:46:00 +00:00
parent 1cf3eee3e6
commit 0d86073f7e

View File

@ -2,6 +2,7 @@ package websocket
import ( import (
"strings" "strings"
"sync"
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
) )
@ -9,6 +10,7 @@ import (
type WebSocket struct { type WebSocket struct {
id string id string
connection *websocket.Conn connection *websocket.Conn
mu sync.Mutex
} }
func (socket *WebSocket) Address() *string { func (socket *WebSocket) Address() *string {
@ -21,6 +23,8 @@ func (socket *WebSocket) Address() *string {
} }
func (socket *WebSocket) Send(v interface{}) error { func (socket *WebSocket) Send(v interface{}) error {
socket.mu.Lock()
defer socket.mu.Unlock()
if socket.connection == nil { if socket.connection == nil {
return nil return nil
} }