Skip to content

Commit

Permalink
cleanup of listeners code, make it neater and a proper name for the file
Browse files Browse the repository at this point in the history
  • Loading branch information
mleku committed Nov 30, 2024
1 parent 4f695ff commit c44ec0b
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions realy/merged.go → realy/listeners.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,31 +62,31 @@ func challenge(conn *websocket.Conn, req *http.Request, addr string) (ws *web.So

func setListener(id S, ws *web.Socket, ff *filters.T) {
listenersMutex.Lock()
defer listenersMutex.Unlock()
subs, ok := listeners[ws]
if !ok {
subs = make(map[S]*Listener)
listeners[ws] = subs
}
subs[id] = &Listener{filters: ff}
listenersMutex.Unlock()
}

func removeListenerId(ws *web.Socket, id S) {
listenersMutex.Lock()
defer listenersMutex.Unlock()
if subs, ok := listeners[ws]; ok {
delete(listeners[ws], id)
if len(subs) == 0 {
delete(listeners, ws)
}
}
listenersMutex.Unlock()
}

func removeListener(ws *web.Socket) {
listenersMutex.Lock()
defer listenersMutex.Unlock()
clear(listeners[ws])
delete(listeners, ws)
listenersMutex.Unlock()
}

func notifyListeners(authRequired bool, ev *event.T) {
Expand Down Expand Up @@ -118,10 +118,10 @@ func notifyListeners(authRequired bool, ev *event.T) {
}
var res *eventenvelope.Result
if res, err = eventenvelope.NewResultWith(id, ev); chk.E(err) {
return
continue
}
if err = res.Write(ws); chk.E(err) {
return
continue
}
}
}
Expand Down

0 comments on commit c44ec0b

Please sign in to comment.