{"id":13560707,"url":"https://github.com/jackc/puddle","last_synced_at":"2025-05-14T02:00:22.250Z","repository":{"id":34899152,"uuid":"162864176","full_name":"jackc/puddle","owner":"jackc","description":"Generic resource pool for Go","archived":false,"fork":false,"pushed_at":"2025-04-26T13:48:29.000Z","size":148,"stargazers_count":361,"open_issues_count":3,"forks_count":31,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-05-03T06:45:18.998Z","etag":null,"topics":["connection","pool","resource"],"latest_commit_sha":null,"homepage":null,"language":"Go","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/jackc.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2018-12-23T05:12:12.000Z","updated_at":"2025-05-02T09:56:47.000Z","dependencies_parsed_at":"2024-01-28T02:24:08.253Z","dependency_job_id":"57f96593-1884-4d45-8d2f-f38cf859b058","html_url":"https://github.com/jackc/puddle","commit_stats":{"total_commits":152,"total_committers":14,"mean_commits":"10.857142857142858","dds":"0.22368421052631582","last_synced_commit":"bd09d14bd4018b6d65a9d7770e2f3ddf8b00af1c"},"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jackc%2Fpuddle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jackc%2Fpuddle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jackc%2Fpuddle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jackc%2Fpuddle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jackc","download_url":"https://codeload.github.com/jackc/puddle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254052658,"owners_count":22006716,"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":["connection","pool","resource"],"created_at":"2024-08-01T13:00:48.886Z","updated_at":"2025-05-14T02:00:22.209Z","avatar_url":"https://github.com/jackc.png","language":"Go","funding_links":[],"categories":["Go","0x05. jackc/puddle"],"sub_categories":[],"readme":"[![Go Reference](https://pkg.go.dev/badge/github.com/jackc/puddle/v2.svg)](https://pkg.go.dev/github.com/jackc/puddle/v2)\n![Build Status](https://github.com/jackc/puddle/actions/workflows/ci.yml/badge.svg)\n\n# Puddle\n\nPuddle is a tiny generic resource pool library for Go that uses the standard\ncontext library to signal cancellation of acquires. It is designed to contain\nthe minimum functionality required for a resource pool. It can be used directly\nor it can be used as the base for a domain specific resource pool. For example,\na database connection pool may use puddle internally and implement health checks\nand keep-alive behavior without needing to implement any concurrent code of its\nown.\n\n## Features\n\n* Acquire cancellation via context standard library\n* Statistics API for monitoring pool pressure\n* No dependencies outside of standard library and golang.org/x/sync\n* High performance\n* 100% test coverage of reachable code\n\n## Example Usage\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"log\"\n\t\"net\"\n\n\t\"github.com/jackc/puddle/v2\"\n)\n\nfunc main() {\n\tconstructor := func(context.Context) (net.Conn, error) {\n\t\treturn net.Dial(\"tcp\", \"127.0.0.1:8080\")\n\t}\n\tdestructor := func(value net.Conn) {\n\t\tvalue.Close()\n\t}\n\tmaxPoolSize := int32(10)\n\n\tpool, err := puddle.NewPool(\u0026puddle.Config[net.Conn]{Constructor: constructor, Destructor: destructor, MaxSize: maxPoolSize})\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\t// Acquire resource from the pool.\n\tres, err := pool.Acquire(context.Background())\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\t// Use resource.\n\t_, err = res.Value().Write([]byte{1})\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\t// Release when done.\n\tres.Release()\n}\n```\n\n## Status\n\nPuddle is stable and feature complete.\n\n* Bug reports and fixes are welcome.\n* New features will usually not be accepted if they can be feasibly implemented in a wrapper.\n* Performance optimizations will usually not be accepted unless the performance issue rises to the level of a bug.\n\n## Supported Go Versions\n\npuddle supports the same versions of Go that are supported by the Go project. For [Go](https://golang.org/doc/devel/release.html#policy) that is the two most recent major releases. This means puddle supports Go 1.19 and higher.\n\n## Differences with Go sync.Pool\n\nThey are intended for entirely different types of resources:\n\n* [sync.Pool](https://pkg.go.dev/sync#Pool) would generally be used for in memory objects.\n* Puddle would generally be used for handles to external objects such as connections, file handles, etc.\n\nSpecific differences:\n\n* sync.Pool does not have a way to limit max resources in pool.\n* sync.Pool does not have a way to ensure at least min resources in pool.\n* sync.Pool can drop resources in pool at any time - not ideal for expensive to create connections.\n* sync.Pool does not have a cleanup / release function. Resources are GCed without a chance to close cleanly.\n* sync.Pool does not have a way to handle errors creating the resource\n* sync.Pool does not support context to limit time to wait creating a resource\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjackc%2Fpuddle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjackc%2Fpuddle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjackc%2Fpuddle/lists"}