From face6df4b610d571c7642369391e7b74042d733c Mon Sep 17 00:00:00 2001 From: Bruce Marriner Date: Fri, 17 Jun 2016 12:24:32 -0500 Subject: [PATCH] Do not call session onEvent as goroutine This is a stability improvement but may have a slight performance impact. This change will be reviewed again later. Doing this solves a data race issue with the Sequence number that must be tracked for gateway resume and heartbeats. Event specific handlers are now called as a goroutine though. --- wsapi.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/wsapi.go b/wsapi.go index 112c16f..ef518a8 100644 --- a/wsapi.go +++ b/wsapi.go @@ -161,7 +161,7 @@ func (s *Session) listen(wsConn *websocket.Conn, listening <-chan interface{}) { return default: - go s.onEvent(messageType, message) + s.onEvent(messageType, message) } } @@ -377,7 +377,7 @@ func (s *Session) onEvent(messageType int, message []byte) { // it's better to pass along what we received than nothing at all. // TODO: Think about that decision :) // Either way, READY events must fire, even with errors. - s.handle(i) + go s.handle(i) } else { s.log(LogWarning, "unknown event: Op: %d, Seq: %d, Type: %s, Data: %s", e.Operation, e.Sequence, e.Type, string(e.RawData)) @@ -385,7 +385,7 @@ func (s *Session) onEvent(messageType int, message []byte) { // Emit event to the OnEvent handler e.Struct = i - s.handle(e) + go s.handle(e) } // ------------------------------------------------------------------------------------------------