fix: moving writeFunc as culprit of memory leak
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user