Merge branch 'master' into master

This commit is contained in:
Dominic Wong 2020-05-29 10:27:20 +01:00 committed by GitHub
commit 73339dde85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -19,12 +19,18 @@ func (p *Pool) Get(id string) (*Socket, bool) {
} }
p.RUnlock() p.RUnlock()
// create new socket
socket = New(id)
// save socket // save socket
p.Lock() p.Lock()
defer p.Unlock()
// double checked locking
socket, ok = p.pool[id]
if ok {
return socket, ok
}
// create new socket
socket = New(id)
p.pool[id] = socket p.pool[id] = socket
p.Unlock()
// return socket // return socket
return socket, false return socket, false
} }