* Run the task with an acquired resource from the pool. If task is completed * successfully, the resource is returned to the pool. Otherwise, the * resource is destroyed. * * @param task - A function that accepts a resource and returns a Promise.
(
task: (resource: T) => ValueOrPromise<void>,
requestCtx: Context = this.context,
)
| 260 | * @param task - A function that accepts a resource and returns a Promise. |
| 261 | */ |
| 262 | async run( |
| 263 | task: (resource: T) => ValueOrPromise<void>, |
| 264 | requestCtx: Context = this.context, |
| 265 | ) { |
| 266 | const resource = await this.acquire(requestCtx); |
| 267 | try { |
| 268 | await task(resource); |
| 269 | } catch (err) { |
| 270 | await this.destroy(resource); |
| 271 | throw err; |
| 272 | } |
| 273 | await this.release(resource); |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | /** |
no test coverage detected