Skip to content

Latest commit

 

History

History
49 lines (38 loc) · 1.95 KB

README.md

File metadata and controls

49 lines (38 loc) · 1.95 KB

resource-pool

Build Status Coverage Status Codacy Badge Version

Pool of cats-effect resources

Features:

  • 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

Example

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
      }
  }

Setup

addSbtPlugin("com.evolution" % "sbt-artifactory-plugin" % "0.0.2")

libraryDependencies += "com.evolution" %% "resource-pool" % "1.0.2"