From 0f530e7902f71c8f66b6b697a7d004e9f45bd9da Mon Sep 17 00:00:00 2001 From: Wim Date: Mon, 5 Sep 2016 23:08:17 +0200 Subject: Fix spinning for loop --- matterclient/matterclient.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/matterclient/matterclient.go b/matterclient/matterclient.go index 0ee8fff1..beb14de0 100644 --- a/matterclient/matterclient.go +++ b/matterclient/matterclient.go @@ -185,7 +185,6 @@ func (m *MMClient) Logout() error { m.WsQuit = true m.WsClient.Close() m.WsClient.UnderlyingConn().Close() - m.WsClient = nil _, err := m.Client.Logout() if err != nil { return err @@ -198,14 +197,16 @@ func (m *MMClient) WsReceiver() { var rawMsg json.RawMessage var err error - if !m.WsConnected { - continue - } if m.WsQuit { m.log.Debug("exiting WsReceiver") return } + if !m.WsConnected { + time.Sleep(time.Millisecond * 100) + continue + } + if _, rawMsg, err = m.WsClient.ReadMessage(); err != nil { m.log.Error("error:", err) // reconnect -- cgit v1.2.3