diff --git a/connection_pool.go b/connection_pool.go index 79626b8d..5e101656 100644 --- a/connection_pool.go +++ b/connection_pool.go @@ -22,16 +22,10 @@ func NewConnectionPool(parameters ConnectionParameters, options ConnectionPoolOp for i := 0; i < p.options.MaxConnections; i++ { var c *Connection - c, err = Connect(p.parameters) + c, err = p.createConnection() if err != nil { return } - if p.options.AfterConnect != nil { - err = p.options.AfterConnect(c) - if err != nil { - return - } - } p.connectionChannel <- c } @@ -60,6 +54,20 @@ func (p *ConnectionPool) Close() { } } +func (p *ConnectionPool) createConnection() (c *Connection, err error) { + c, err = Connect(p.parameters) + if err != nil { + return + } + if p.options.AfterConnect != nil { + err = p.options.AfterConnect(c) + if err != nil { + return + } + } + return +} + // SelectFunc acquires a connection, delegates the call to that connection, and releases the connection func (p *ConnectionPool) SelectFunc(sql string, onDataRow func(*DataRowReader) error, arguments ...interface{}) (err error) { c := p.Acquire()