Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/evolution-gaming/resource-pool
Pool of cats-effect resources
https://github.com/evolution-gaming/resource-pool
connection-pool pool resource resource-pool scala
Last synced: about 2 months ago
JSON representation
Pool of cats-effect resources
- Host: GitHub
- URL: https://github.com/evolution-gaming/resource-pool
- Owner: evolution-gaming
- License: mit
- Created: 2023-09-15T08:17:40.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-11-08T12:09:31.000Z (2 months ago)
- Last Synced: 2024-11-08T12:34:32.586Z (2 months ago)
- Topics: connection-pool, pool, resource, resource-pool, scala
- Language: Scala
- Homepage: https://github.com/evolution-gaming/resource-pool
- Size: 112 KB
- Stars: 3
- Watchers: 2
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# resource-pool
[![Build Status](https://github.com/evolution-gaming/resource-pool/workflows/CI/badge.svg)](https://github.com/evolution-gaming/resource-pool/actions?query=workflow%3ACI)
[![Coverage Status](https://coveralls.io/repos/github/evolution-gaming/resource-pool/badge.svg?branch=main)](https://coveralls.io/github/evolution-gaming/resource-pool?branch=main)
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/879e88a4e6a94647848bc6b45788a9d7)](https://app.codacy.com/gh/evolution-gaming/resource-pool/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
[![Version](https://img.shields.io/badge/version-click-blue)](https://evolution.jfrog.io/artifactory/api/search/latestVersion?g=com.evolution&a=resource-pool_2.13&repos=public)Pool of [cats-effect](https://typelevel.org/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
```scala
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
```scala
addSbtPlugin("com.evolution" % "sbt-artifactory-plugin" % "0.0.2")libraryDependencies += "com.evolution" %% "resource-pool" % "1.0.2"
```