优化接入网关,解决协程泄漏的问题

This commit is contained in:
dushixiang
2022-05-07 16:48:05 +08:00
parent 41768cbec9
commit 5695d6b2e2
16 changed files with 158 additions and 191 deletions

View File

@ -0,0 +1,15 @@
package utils
import "sync"
type KeyedMutex struct {
mutexes sync.Map // Zero value is empty and ready for use
}
func (m *KeyedMutex) Lock(key string) func() {
value, _ := m.mutexes.LoadOrStore(key, &sync.Mutex{})
mtx := value.(*sync.Mutex)
mtx.Lock()
return func() { mtx.Unlock() }
}