From ebdb3827065b2d37c1da992e7abf610f5376146b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ken-H=C3=A5vard=20Lieng?= Date: Sat, 6 Jun 2015 01:02:02 +0200 Subject: [PATCH] Stop creating new goroutines for irc.Connect() since it doesnt block anymore --- server/server.go | 21 +++++++++------------ server/websocket_handler.go | 24 +++++++++++------------- 2 files changed, 20 insertions(+), 25 deletions(-) diff --git a/server/server.go b/server/server.go index 9279270d..b79aea95 100644 --- a/server/server.go +++ b/server/server.go @@ -69,20 +69,17 @@ func reconnect() { i.Password = server.Password i.Realname = server.Realname - go func(server storage.Server) { - i.Connect(server.Address) - session.setIRC(i.Host, i) + i.Connect(server.Address) + session.setIRC(i.Host, i) + go handleIRC(i, session) - go handleIRC(i, session) - - var joining []string - for _, channel := range channels { - if channel.Server == server.Address { - joining = append(joining, channel.Name) - } + var joining []string + for _, channel := range channels { + if channel.Server == server.Address { + joining = append(joining, channel.Name) } - i.Join(joining...) - }(server) + } + i.Join(joining...) } } } diff --git a/server/websocket_handler.go b/server/websocket_handler.go index 99554a61..30190d0d 100644 --- a/server/websocket_handler.go +++ b/server/websocket_handler.go @@ -99,20 +99,18 @@ func handleWS(conn *websocket.Conn) { session.setIRC(data.Server[:idx], i) } - go func() { - i.Connect(data.Server) - go handleIRC(i, session) + i.Connect(data.Server) + go handleIRC(i, session) - session.user.AddServer(storage.Server{ - Name: data.Name, - Address: i.Host, - TLS: data.TLS, - Password: data.Password, - Nick: data.Nick, - Username: data.Username, - Realname: data.Realname, - }) - }() + session.user.AddServer(storage.Server{ + Name: data.Name, + Address: i.Host, + TLS: data.TLS, + Password: data.Password, + Nick: data.Nick, + Username: data.Username, + Realname: data.Realname, + }) } else { log.Println(addr, "already connected to", data.Server) }