Fix a panic on close bug (#28)

Co-authored-by: James Mills <prologic@shortcircuit.net.au>
Reviewed-on: https://git.mills.io/prologic/msgbus/pulls/28
This commit is contained in:
James Mills 2022-04-02 14:50:42 +00:00
parent 7b71102aa8
commit 5c065e91ed

View File

@ -199,9 +199,11 @@ func NewSubscriber(client *Client, topic string, index int, handler msgbus.Handl
func (s *Subscriber) closeAndReconnect() {
s.RLock()
s.conn.Close(websocket.StatusNormalClosure, "Closing and reconnecting...")
if s.conn != nil {
s.conn.Close(websocket.StatusNormalClosure, "Closing and reconnecting...")
go s.connect()
}
s.RUnlock()
go s.connect()
}
func (s *Subscriber) connect() {