Improve remove empty map on websocket unsubscribe

pull/401/head
Martin Boehm 2020-03-17 00:08:00 +01:00
parent c2e32b0a25
commit 2a3c5426ca
1 changed files with 7 additions and 4 deletions

View File

@ -688,11 +688,11 @@ func (s *WebsocketServer) unsubscribeAddresses(c *websocketChannel) (res interfa
for sc := range sa {
if sc == c {
delete(sa, c)
if len(sa) == 0 {
delete(s.addressSubscriptions, ads)
}
}
}
if len(sa) == 0 {
delete(s.addressSubscriptions, ads)
}
}
return &subscriptionResponse{false}, nil
}
@ -720,12 +720,15 @@ func (s *WebsocketServer) subscribeFiatRates(c *websocketChannel, currency strin
func (s *WebsocketServer) unsubscribeFiatRates(c *websocketChannel) (res interface{}, err error) {
s.fiatRatesSubscriptionsLock.Lock()
defer s.fiatRatesSubscriptionsLock.Unlock()
for _, sa := range s.fiatRatesSubscriptions {
for fr, sa := range s.fiatRatesSubscriptions {
for sc := range sa {
if sc == c {
delete(sa, c)
}
}
if len(sa) == 0 {
delete(s.fiatRatesSubscriptions, fr)
}
}
return &subscriptionResponse{false}, nil
}