mirror of https://github.com/jackc/pgx.git
pool-queue-vs-stack pool should work like a queue to traverse all possible connections
parent
e44f0f24c4
commit
00d38a68a8
10
conn_pool.go
10
conn_pool.go
|
@ -116,10 +116,14 @@ func (p *ConnPool) acquire(deadline *time.Time) (*Conn, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// A connection is available
|
// A connection is available
|
||||||
if len(p.availableConnections) > 0 {
|
// The pool works like a queue. Available connection will be returned
|
||||||
c := p.availableConnections[len(p.availableConnections)-1]
|
// from the head. A new connection will be added to the tail.
|
||||||
|
numAvailable := len(p.availableConnections)
|
||||||
|
if numAvailable > 0 {
|
||||||
|
c := p.availableConnections[0]
|
||||||
c.poolResetCount = p.resetCount
|
c.poolResetCount = p.resetCount
|
||||||
p.availableConnections = p.availableConnections[:len(p.availableConnections)-1]
|
copy(p.availableConnections, p.availableConnections[1:])
|
||||||
|
p.availableConnections = p.availableConnections[:numAvailable-1]
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue