Chat server: Difference between revisions

→‎{{header|Go}}: fix data race on `s.add` (and move other channel makes just to keep them together)
m (→‎{{header|Go}}: fix minor comment typo)
(→‎{{header|Go}}: fix data race on `s.add` (and move other channel makes just to keep them together))
Line 737:
log.Println("Listening for connections on", addr)
defer ln.Close()
s := &Server{stop: make(chan bool)}
s. add: = make(chan *conn),
s. rem: = make(chan string),
s. msg: = make(chan string[]byte),
stop: make(chan bool),
}
go s.handleConns()
for {
Line 757 ⟶ 762:
// chat client connections as well as broadcasting messages to them.
func (s *Server) handleConns() {
s.add = make(chan *conn)
s.rem = make(chan string)
s.msg = make(chan string)
 
// We define the `conns` map here rather than within Server,
// and we use local function literals rather than methods to be
Anonymous user