Compare commits

..

2 Commits

2 changed files with 9 additions and 2 deletions

View File

@@ -294,6 +294,11 @@ func (wsClient *SafeWebsocketClient) reconnectHandler() {
default: // prevent blocking if chan is full
}
}
if len(wsClient.reconnectChans) > 1 {
wsClient.reconnectChans = wsClient.reconnectChans[1:]
} else {
wsClient.reconnectChans = nil
}
}
case <-wsClient.ctx.Done():
log.Println("reconnect handler stopped due to client shutdown")

View File

@@ -64,10 +64,12 @@ func (b *SafeWebsocketServerBuilder) HandleFunc(pattern string, fn func(http.Res
return b
}
func (b *SafeWebsocketServerBuilder) HandleFuncWebsocket(pattern string, subscribedPath string, writeFunc func(chan []byte)) *SafeWebsocketServerBuilder {
func (b *SafeWebsocketServerBuilder) HandleFuncWebsocket(pattern string, subscribedPath string, writeFunc func(writeChannel chan []byte)) *SafeWebsocketServerBuilder {
h := internal.NewHub()
h.Run()
go writeFunc(h.Broadcast)
b.mux.HandleFunc(pattern+subscribedPath, func(w http.ResponseWriter, r *http.Request) {
conn, err := b.upgrader.Upgrade(w, r, nil)
if err != nil {
@@ -85,7 +87,7 @@ func (b *SafeWebsocketServerBuilder) HandleFuncWebsocket(pattern string, subscri
go internal.WritePump(c, h)
go internal.ReadPump(c, h)
go writeFunc(h.Broadcast)
})
return b
}