GetConn returns connection from the pool or create new
(ctx context.Context)
| 145 | |
| 146 | // GetConn returns connection from the pool or create new |
| 147 | func (pool *Pool) GetConn(ctx context.Context) (*Conn, error) { |
| 148 | for { |
| 149 | connection, err := pool.getConnection(ctx) |
| 150 | if err != nil { |
| 151 | return nil, err |
| 152 | } |
| 153 | |
| 154 | // For long time idle connections, we do a ping check |
| 155 | if delta := pool.nowTs() - connection.lastUseAt; delta > pool.idlePingTimeout { |
| 156 | if err := pool.ping(connection.conn); err != nil { |
| 157 | pool.closeConn(connection.conn) |
| 158 | continue |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | return connection.conn, nil |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | // PutConn returns working connection back to pool |
| 167 | func (pool *Pool) PutConn(conn *Conn) { |
no test coverage detected