mirror of
https://github.com/bbernhard/signal-cli-rest-api.git
synced 2026-11-02 09:59:33 +00:00
Shorten the critical section
This commit is contained in:
parent
2cb7ad4fb1
commit
090d9b135e
@ -347,26 +347,30 @@ func (r *JsonRpc2Client) acquireReceiveSubscription(account string) error {
|
||||
|
||||
func (r *JsonRpc2Client) releaseReceiveSubscription(account string) error {
|
||||
r.receiveSubscriptionsMutex.Lock()
|
||||
defer r.receiveSubscriptionsMutex.Unlock()
|
||||
|
||||
sub, ok := r.receiveSubscriptions[account]
|
||||
if !ok {
|
||||
r.receiveSubscriptionsMutex.Unlock()
|
||||
return nil
|
||||
}
|
||||
|
||||
sub.refcount--
|
||||
if sub.refcount > 0 {
|
||||
r.receiveSubscriptionsMutex.Unlock()
|
||||
return nil
|
||||
}
|
||||
|
||||
delete(r.receiveSubscriptions, account)
|
||||
err := r.unsubscribeReceive(account, sub.id)
|
||||
|
||||
r.receiveSubscriptionsMutex.Unlock()
|
||||
|
||||
if err != nil {
|
||||
log.Warnf("Couldn't unsubscribed from receive notifications for account %s (subscription=%d): %s", account, sub.id, err.Error())
|
||||
} else {
|
||||
log.Debugf("Unsubscribed from receive notifications for account %s (subscription=%d)", account, sub.id)
|
||||
}
|
||||
|
||||
delete(r.receiveSubscriptions, account)
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user