* [use method, aquires a resource, passes the resource to a user supplied function and releases it] * @param {Function} fn [a function that accepts a resource and returns a promise that resolves/rejects once it has finished using the resource] * @return {Promise} [resolves once the resou
(fn, priority)
| 476 | * @return {Promise} [resolves once the resource is released to the pool] |
| 477 | */ |
| 478 | use(fn, priority) { |
| 479 | return this.acquire(priority).then(resource => { |
| 480 | return fn(resource).then( |
| 481 | result => { |
| 482 | this.release(resource); |
| 483 | return result; |
| 484 | }, |
| 485 | err => { |
| 486 | this.destroy(resource); |
| 487 | throw err; |
| 488 | } |
| 489 | ); |
| 490 | }); |
| 491 | } |
| 492 | |
| 493 | /** |
| 494 | * Check if resource is currently on loan from the pool |
no test coverage detected