* Release the resource back to the pool. * @param resource - Resource instance to be returned back to the pool
(resource: T)
| 214 | * @param resource - Resource instance to be returned back to the pool |
| 215 | */ |
| 216 | async release(resource: T) { |
| 217 | debug( |
| 218 | 'Releasing a resource from the pool in context %s', |
| 219 | this.context.name, |
| 220 | resource, |
| 221 | ); |
| 222 | try { |
| 223 | // Try factory-level acquire hook first |
| 224 | if (this.factory.release) { |
| 225 | await this.factory.release(resource); |
| 226 | } else { |
| 227 | await invokePoolableMethod(resource as Poolable, 'release'); |
| 228 | } |
| 229 | await this.pool.release(resource); |
| 230 | } catch (err) { |
| 231 | await this.pool.destroy(resource); |
| 232 | throw err; |
| 233 | } |
| 234 | debug( |
| 235 | 'Resource released to the pool in context %s', |
| 236 | this.context.name, |
| 237 | resource, |
| 238 | ); |
| 239 | } |
| 240 | |
| 241 | /** |
| 242 | * Destroy a resource from the pool |
no test coverage detected