keypool icon indicating copy to clipboard operation
keypool copied to clipboard

Implement blockWhenExhausted

Open rossabaker opened this issue 1 year ago • 0 comments

commons-pool2 functionality

In commons-pool2, borrowObject, when no object is available, it may immediately raise an error or block for a specified duration, depending on the blockWhenExhausted property.

Current behavior

keypool effectively hardcodes this to true with semantic blocking. The effect can be canceled, so the duration can be emulated with a simple Cats Effect timeout. There is not presently a way to immediately fail, similar to tryAcquire on a Semaphore.

Analysis

It is not clear why this should be a property on the pool rather than an operation on the caller. A tryTake: Resource[F, Option[Managed[F]] is a possibility.

Workarounds

timeout with a short enough duration to not introduce lag, but a long enough duration to not generate false positives.

rossabaker avatar Jun 26 '24 02:06 rossabaker