keypool icon indicating copy to clipboard operation
keypool copied to clipboard

A resource can be acquired even from the closed pool

Open iRevive opened this issue 4 years ago • 0 comments

keypool version: 0.4.7

Even when the state of the pool is PoolClosed a new resource can still be acquired.
Should an exception be thrown at this case?

Example:

val pool = KeyPool
  .Builder(
    (i: Int) => IO.ref(i),
    (r: Ref[IO, Int]) => IO.unit
  )
  .build
  
for {
  closedPool <- pool.use(kp => IO.pure(kp)) 
  _          <- closedPool.take(1).use { ref => 
    ref.get.flatMap(value => IO.println(s"created a new ref in the closed pool: $value"))
  }
} yield ()

Output:

created a new ref in the closed pool: 1

iRevive avatar Nov 09 '21 14:11 iRevive