pool: close all connections at once.

This commit is contained in:
Vladimir Mihailenco 2015-06-03 14:50:43 +03:00
parent fc04a09033
commit 7d886330f1
1 changed files with 4 additions and 8 deletions

12
pool.go
View File

@ -278,17 +278,13 @@ func (p *connPool) Close() (retErr error) {
if !atomic.CompareAndSwapInt32(&p._closed, 0, 1) {
return errClosed
}
// First close free connections.
for p.Len() > 0 {
cn := p.wait()
if cn == nil {
// Wait for app to free connections, but don't close them immediately.
for i := 0; i < p.Len(); i++ {
if cn := p.wait(); cn == nil {
break
}
if err := p.conns.Remove(cn); err != nil {
retErr = err
}
}
// Then close the rest.
// Close all connections.
if err := p.conns.Close(); err != nil {
retErr = err
}