{"id":16451724,"url":"https://github.com/tpolecat/pool-party","last_synced_at":"2025-03-21T05:30:38.065Z","repository":{"id":45445498,"uuid":"383888746","full_name":"tpolecat/pool-party","owner":"tpolecat","description":"Turn a normal resource into a pooled one.","archived":false,"fork":false,"pushed_at":"2022-11-23T20:25:42.000Z","size":1357,"stargazers_count":39,"open_issues_count":2,"forks_count":3,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-20T15:58:13.373Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tpolecat.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-07-07T18:18:09.000Z","updated_at":"2025-03-14T11:17:07.000Z","dependencies_parsed_at":"2022-07-30T17:38:05.761Z","dependency_job_id":null,"html_url":"https://github.com/tpolecat/pool-party","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tpolecat%2Fpool-party","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tpolecat%2Fpool-party/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tpolecat%2Fpool-party/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tpolecat%2Fpool-party/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tpolecat","download_url":"https://codeload.github.com/tpolecat/pool-party/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244745641,"owners_count":20503043,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-11T10:10:08.925Z","updated_at":"2025-03-21T05:30:37.567Z","avatar_url":"https://github.com/tpolecat.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Pool Party!\n\n[![Discord](https://img.shields.io/discord/632277896739946517.svg?label=\u0026logo=discord\u0026logoColor=ffffff\u0026color=404244\u0026labelColor=6A7EC2)](https://sca.la/typeleveldiscord)\n[![Maven Central](https://img.shields.io/maven-central/v/org.tpolecat/pool-party_2.13.svg)](https://maven-badges.herokuapp.com/maven-central/org.tpolecat/pool-party_2.13)\n[![Javadocs](https://javadoc.io/badge/org.tpolecat/pool-party_2.13.svg)](https://javadoc.io/doc/org.tpolecat/pool-party_2.13)\n\n\n![Pool full of scary monsters.](pool.jpg)\n\n**Pool Party** is a Scala micro-library that turns a regular `cats.effect.Resource` into a non-blocking, fixed-size pooled resource with optional health checking and event reporting. **This is pre-release software** so it may cause your data center to burn down or (worse) not burn down. Either way it's not my problem.\n\n**Pool Party** is published for Scala 2.13/3.0 and you can include it in your project thus:\n\n```scala\nlibraryDependencies += \"org.tpolecat\" %% \"pool-party\" % \u003cversion\u003e\n```\n\n### Usage\n\n`PooledResourceBuilder` builds a resource that yields a pooled version of some other underlying\nresource that you provide.\n\n```scala\nval r: Resource[F, Woozle] = ... // A limited resource\n\nPooledResourceBuilder.of(r, 10).build.use { pool =\u003e\n  // `pool` has the same apparent behavior as `r`, but will never allow more than\n  // 10 concurrent `Woozle`s, which will be recycled and reused on return.\n}\n```\n\nIn most cases you will create a pool when your program starts, and it will not be finalized until the program shuts down. In the common case for a web app your `IOApp.run` will look something like:\n\n```scala\n// A server is usually a resource you hang onto until someone hits ^C.\ndef run(args: List[String]): IO[ExitCode] =\n  runResource[IO](args).use(_ =\u003e IO.never)\n\n// That resource is the composition of many things, including our pool.\ndef runResource[F[_]: Temporal: OtherStuff](args: List[String]): Resource[F, ExitCode] =\n  for {\n    ...\n    pool \u003c- PoolBuilder.of(...).withHealthCheck(...).withReporter(...).build\n    ...  \u003c- httpServerResource(pool, etc) // request handler can say pool.use\n  } yield ExitCode.Success\n```\n\nWhat you **don't** want to do is create a new pool for each request. It's a common error that defeats the purpose of pooling.\n\n### Configuration\n\nIn addition to the pool size (required), `PooledResourceBuilder` provides the following configurable properties:\n\n| Property | Type | Explanation |\n|---|---|--|\n|`HealthCheck` | `A =\u003e F[Boolean]` | Check the health of a pooled instance after it's returned to the pool, and perform any necessary cleanup. Yield `false` if the instance should be finalized and discarded. Default behavior always yields `true`. |\n|`ShutdownTimeout` | `FiniteDuration` | Amount of time to wait for pooled instances to be finalized when the pool shuts down by leaving `.use` scope. Default is `Long.MaxValue.ns` (~292 years). |\n|`Reporter` | `PoolEvent[A] =\u003e F[Unit]` | Callback that will receive events about the pool's lifecycle, including error conditions that you probably want to know about. So it's usually a good idea to specify this. The default behavior does nothing. |\n\nNote that the `Reporter` is invoked **synchronously** so it should not do anything time-consuming. A production reporter might enqueue events for later asynchronous processing.\n\n### Getting Help\n\nFirst check out the [Scaladoc](https://javadoc.io/doc/org.tpolecat/pool-party_2.13), and if you're\nstill in trouble please open an issue or find me on the [Typelevel Discord](https://sca.la/typeleveldiscord).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftpolecat%2Fpool-party","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftpolecat%2Fpool-party","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftpolecat%2Fpool-party/lists"}