Adapt With Close
This commit is contained in:
@@ -237,7 +237,19 @@ func (o *PeerController) DeleteState() {
|
||||
|
||||
func Websocket(ctx ctx.Context, user string, r http.ResponseWriter, w *http.Request) {
|
||||
websocket.Handler(func(ws *websocket.Conn) {
|
||||
defer ws.Close()
|
||||
defer func() {
|
||||
ws.Close()
|
||||
infrastructure.SearchMu.Lock()
|
||||
if ch, ok := infrastructure.SearchStream[user]; ok {
|
||||
close(ch)
|
||||
delete(infrastructure.SearchStream, user)
|
||||
}
|
||||
infrastructure.SearchMu.Unlock()
|
||||
infrastructure.EmitNATS(user, nil, tools.PropalgationMessage{
|
||||
Action: tools.PB_CLOSE_SEARCH,
|
||||
DataType: tools.PEER.EnumIndex(),
|
||||
})
|
||||
}()
|
||||
for msg := range infrastructure.SearchStream[user] {
|
||||
if websocket.JSON.Send(ws, msg) != nil {
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user