remove all subscription in Disconnect

remove subscription in unsubscribe
This commit is contained in:
Marcelo Pires 2018-09-06 15:37:42 +02:00
parent 01f041d2fc
commit 8e2c2327d5

View File

@ -202,6 +202,12 @@ func (w *Websocket) Disconnect() error {
w.stopCh <- nil
close(w.stopCh)
w.subsMu.Lock()
for i := range w.subs {
close(w.subs[i])
delete(w.subs, i)
}
w.subsMu.Unlock()
return w.sendMessage(&m)
}
@ -245,6 +251,14 @@ func (w *Websocket) Unsubscribe(subscription string) error {
ClientId: w.clientID,
Id: w.nextMsgID(),
}
w.subsMu.Lock()
sub, ok := w.subs[subscription]
if ok {
close(sub)
delete(w.subs, subscription)
}
w.subsMu.Unlock()
return w.sendMessage(m)
}