Bläddra i källkod

Reduce memory used in chat example

Gary Burd 8 år sedan
förälder
incheckning
ea4d1f681b
1 ändrade filer med 4 tillägg och 1 borttagningar
  1. 4 1
      examples/chat/client.go

+ 4 - 1
examples/chat/client.go

@@ -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()
 }