use a named lock instead of a single per-pool mutex.

This commit is contained in:
fiatjaf
2023-08-06 19:54:30 -03:00
parent 2e9cdc8255
commit b522d24c30
2 changed files with 13 additions and 3 deletions
+1 -3
View File
@@ -13,7 +13,6 @@ type SimplePool struct {
Relays map[string]*Relay
Context context.Context
mutex sync.Mutex
cancel context.CancelFunc
}
@@ -31,8 +30,7 @@ func NewSimplePool(ctx context.Context) *SimplePool {
func (pool *SimplePool) EnsureRelay(url string) (*Relay, error) {
nm := NormalizeURL(url)
pool.mutex.Lock()
defer pool.mutex.Unlock()
defer namedLock(url)()
relay, ok := pool.Relays[nm]
if ok && relay.IsConnected() {