Pool of cats-effect resources
- allocates resources on demand up to configured limit
- deallocates resources if not active for a configured time
- tries to minimize number of resources in the pool
- uses first-in-first-out queue for tasks
- shuts down gracefully after completing accumulated tasks
- tolerates resource failures
- supports cancellation
import com.evolution.resourcepool.ResourcePool.implicits.*
trait Connection {
def query(): IO[Any]
}
def connection: Resource[IO, Connection] = ???
connection
.toResourcePool( // you can convert any resource into the pool of resources
maxSize = 10, // it will create up to `maxSize` connections
expireAfter = 1.minute) // pool will release connection if it is not used for 1 minute
.use { connectionPool =>
connectionPool
.resource // this will get first available connection or allocate one
.use { connection =>
connection.query() // here you have access to the connection
}
}
addSbtPlugin("com.evolution" % "sbt-artifactory-plugin" % "0.0.2")
libraryDependencies += "com.evolution" %% "resource-pool" % "1.0.2"