test mutex (#158)

Co-authored-by: callebtc <93376500+callebtc@users.noreply.github.com>
This commit is contained in:
LightningTipBot 2021-12-08 22:22:11 +01:00 committed by GitHub
parent 1b922c03a9
commit f50e6ced71
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -47,7 +47,9 @@ func (bot TipBot) unlockInterceptor(ctx context.Context, i interface{}) (context
user := getTelegramUserFromInterface(i)
if user != nil {
handlerMapMutex.Lock()
handlerMutex[user.ID].Unlock()
if handlerMutex[user.ID] != nil {
handlerMutex[user.ID].Unlock()
}
handlerMapMutex.Unlock()
}
return ctx, nil
@ -58,10 +60,10 @@ func (bot TipBot) lockInterceptor(ctx context.Context, i interface{}) (context.C
user := getTelegramUserFromInterface(i)
if user != nil {
handlerMapMutex.Lock()
defer handlerMapMutex.Unlock()
if handlerMutex[user.ID] == nil {
handlerMutex[user.ID] = &sync.Mutex{}
}
handlerMapMutex.Unlock()
handlerMutex[user.ID].Lock()
return ctx, nil
}