mirror of
https://github.com/ChuckNorrison/LightningTipBot.git
synced 2026-08-15 12:50:37 +02:00
test mutex (#158)
Co-authored-by: callebtc <93376500+callebtc@users.noreply.github.com>
This commit is contained in:
parent
1b922c03a9
commit
f50e6ced71
1 changed files with 4 additions and 2 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue