Reduce memory used in chat example

This commit is contained in:
Gary Burd 2017-06-20 12:01:03 -07:00
parent a91eba7f97
commit ea4d1f681b
1 changed files with 4 additions and 1 deletions

View File

@ -129,6 +129,9 @@ func serveWs(hub *Hub, w http.ResponseWriter, r *http.Request) {
}
client := &Client{hub: hub, conn: conn, send: make(chan []byte, 256)}
client.hub.register <- client
// Allow collection of memory referenced by the caller by doing all work in
// new goroutines.
go client.writePump()
client.readPump()
go client.readPump()
}