summaryrefslogtreecommitdiffstats
path: root/app/web_conn.go
diff options
context:
space:
mode:
authorChris <ccbrown112@gmail.com>2017-10-03 10:53:53 -0500
committerGitHub <noreply@github.com>2017-10-03 10:53:53 -0500
commit5e69ce099f521aa49fc267c62235c003eae530ff (patch)
treec7177e4cac419082753225819f62d07c8b5671e8 /app/web_conn.go
parentbfe7955fb0c72bb6f3e0a1e0aaca70cff27d7ddc (diff)
downloadchat-5e69ce099f521aa49fc267c62235c003eae530ff.tar.gz
chat-5e69ce099f521aa49fc267c62235c003eae530ff.tar.bz2
chat-5e69ce099f521aa49fc267c62235c003eae530ff.zip
Goroutine wranglin (#7556)
* goroutine wranglin * synchronize WebConn.WritePump
Diffstat (limited to 'app/web_conn.go')
-rw-r--r--app/web_conn.go22
1 files changed, 18 insertions, 4 deletions
diff --git a/app/web_conn.go b/app/web_conn.go
index f5644ce17..5f66d9a51 100644
--- a/app/web_conn.go
+++ b/app/web_conn.go
@@ -44,10 +44,10 @@ type WebConn struct {
func (a *App) NewWebConn(ws *websocket.Conn, session model.Session, t goi18n.TranslateFunc, locale string) *WebConn {
if len(session.UserId) > 0 {
- go func() {
+ a.Go(func() {
a.SetStatusOnline(session.UserId, session.Id, false)
a.UpdateLastActivityAtIfNeeded(session)
- }()
+ })
}
wc := &WebConn{
@@ -94,6 +94,16 @@ func (c *WebConn) SetSession(v *model.Session) {
c.session.Store(v)
}
+func (c *WebConn) Pump() {
+ ch := make(chan struct{}, 1)
+ go func() {
+ c.WritePump()
+ ch <- struct{}{}
+ }()
+ c.ReadPump()
+ <-ch
+}
+
func (c *WebConn) ReadPump() {
defer func() {
c.App.HubUnregister(c)
@@ -104,7 +114,9 @@ func (c *WebConn) ReadPump() {
c.WebSocket.SetPongHandler(func(string) error {
c.WebSocket.SetReadDeadline(time.Now().Add(PONG_WAIT))
if c.IsAuthenticated() {
- go c.App.SetStatusAwayIfNeeded(c.UserId, false)
+ c.App.Go(func() {
+ c.App.SetStatusAwayIfNeeded(c.UserId, false)
+ })
}
return nil
})
@@ -191,7 +203,9 @@ func (c *WebConn) WritePump() {
}
if c.App.Metrics != nil {
- go c.App.Metrics.IncrementWebSocketBroadcast(msg.EventType())
+ c.App.Go(func() {
+ c.App.Metrics.IncrementWebSocketBroadcast(msg.EventType())
+ })
}
}