Add in the optimization where multiple websocket events can exist within a single message
This commit is contained in:
@@ -135,6 +135,14 @@ func (c *ChatClient) writePump() {
|
||||
log.Debugln(err)
|
||||
}
|
||||
|
||||
// Optimization: Send multiple events in a single websocket message.
|
||||
// Add queued chat messages to the current websocket message.
|
||||
n := len(c.send)
|
||||
for i := 0; i < n; i++ {
|
||||
_, _ = w.Write(newline)
|
||||
_, _ = w.Write(<-c.send)
|
||||
}
|
||||
|
||||
if err := w.Close(); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user