Skip to content

Commit

Permalink
concurrent map read 😒
Browse files Browse the repository at this point in the history
  • Loading branch information
monoxane committed Mar 12, 2023
1 parent 13e99ef commit 6ae350b
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package main
import (
"log"
"net/http"
"sync"

"github.com/gin-gonic/gin"
"github.com/gorilla/websocket"
Expand Down Expand Up @@ -92,6 +93,8 @@ type ProbeSocketHandler struct {
broadcast chan *[]byte

upgrader *websocket.Upgrader

mux sync.Mutex
}

func (h *ProbeSocketHandler) Run() {
Expand Down Expand Up @@ -138,7 +141,9 @@ func (h *ProbeSocketHandler) ServeWS(c *gin.Context) {
}

func (h *ProbeSocketHandler) BroadcastData(data *[]byte) {
h.mux.Lock()
for client := range h.clients {
client.sendChan <- data
}
h.mux.Unlock()
}

0 comments on commit 6ae350b

Please sign in to comment.