{"id":21178683,"url":"https://github.com/poabob/grpool","last_synced_at":"2025-03-14T18:43:26.429Z","repository":{"id":194440686,"uuid":"690841196","full_name":"POABOB/grpool","owner":"POABOB","description":"A Practical Goroutine Pool and Easy to Use.","archived":false,"fork":false,"pushed_at":"2023-09-18T14:32:58.000Z","size":61,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-21T11:45:14.418Z","etag":null,"topics":["go","golang","goroutine-pool","goroutines"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/POABOB/grpool","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/POABOB.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-09-13T01:52:01.000Z","updated_at":"2024-10-02T16:23:10.000Z","dependencies_parsed_at":null,"dependency_job_id":"2f437fba-4830-416d-82d0-1f093f0102f1","html_url":"https://github.com/POABOB/grpool","commit_stats":null,"previous_names":["poabob/grpool"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/POABOB%2Fgrpool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/POABOB%2Fgrpool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/POABOB%2Fgrpool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/POABOB%2Fgrpool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/POABOB","download_url":"https://codeload.github.com/POABOB/grpool/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243629222,"owners_count":20322017,"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":["go","golang","goroutine-pool","goroutines"],"created_at":"2024-11-20T17:23:24.109Z","updated_at":"2025-03-14T18:43:26.407Z","avatar_url":"https://github.com/POABOB.png","language":"Go","readme":"# grpool\r\n\r\n\u003ca title=\"Build Status\" target=\"_blank\" href=\"https://github.com/POABOB/grpool/actions?query=workflow%3AGo\"\u003e\u003cimg src=\"https://img.shields.io/github/actions/workflow/status/POABOB/grpool/go.yaml?branch=main\u0026style=flat-square\u0026logo=github-actions\" /\u003e\u003c/a\u003e\r\n\u003ca title=\"Release\" target=\"_blank\" href=\"https://github.com/POABOB/grpool/releases\"\u003e\u003cimg src=\"https://img.shields.io/github/v/release/POABOB/grpool.svg?color=166823\u0026style=flat-square\u0026logo=smartthings\" /\u003e\u003c/a\u003e\r\n\u003ca title=\"Go Report Card\" target=\"_blank\" href=\"https://goreportcard.com/report/github.com/POABOB/grpool\"\u003e\u003cimg src=\"https://goreportcard.com/badge/github.com/POABOB/grpool?style=flat-square\" /\u003e\u003c/a\u003e\r\n\u003ca title=\"Codecov\" target=\"_blank\" href=\"https://codecov.io/gh/POABOB/grpool\"\u003e\u003cimg src=\"https://img.shields.io/codecov/c/github/POABOB/grpool?style=flat-square\u0026logo=codecov\" /\u003e\u003c/a\u003e\r\n\r\n## Introduction\r\n\r\n`grpool` is a groutine pool which can provide a fixed size of capacity, recycle the stale workers. \r\n\r\n## Installation\r\n\r\n```bash\r\ngo get -u github.com/POABOB/grpool\r\n```\r\n\r\n## How to use\r\n\r\nIf you want to process a massive number of jobs, you don't need to use the same number of goroutines. It's wasteful to use excessive memory, leading to high consumption.\r\n\r\n### A Simple Example with Default Pool\r\n\r\n```go\r\npackage main\r\n\r\nimport (\r\n\t\"fmt\"\r\n\t\"strconv\"\r\n\t\"sync\"\r\n\t\"sync/atomic\"\r\n\r\n\t\"github.com/POABOB/grpool\"\r\n)\r\n\r\nvar wg sync.WaitGroup\r\nvar count int32 = 0\r\n\r\nfunc main() {\r\n\t// Use default Pool Will use the math.MaxInt32 of capacity.\r\n\tpool := grpool.NewDefaultPool()\r\n\t// Release worker resource\r\n\tdefer pool.Release()\r\n\r\n\tfor i := 0; i \u003c 10000; i++ {\r\n\t\twg.Add(1)\r\n\t\t_ = pool.Schedule(func() {\r\n\t\t\tprintFunc(i)\r\n\t\t})\r\n\t}\r\n\r\n\twg.Wait()\r\n    \r\n\tfmt.Printf(\"running goroutines: %d\\n\", pool.Running())\r\n}\r\n\r\nfunc printFunc(i int) {\r\n\tatomic.AddInt32(\u0026count, 1)\r\n\tfmt.Println(\"Hello World! I am worker\" + strconv.Itoa(i) + \" from goroutine pool.\")\r\n\twg.Done()\r\n}\r\n```\r\n\r\n### Limit the goroutines and pre-alloc it\r\n\r\n```go\r\npackage main\r\n\r\nimport (\r\n\t\"fmt\"\r\n\t\"strconv\"\r\n\t\"sync\"\r\n\t\"sync/atomic\"\r\n\r\n\t\"github.com/POABOB/grpool\"\r\n)\r\n\r\nvar count int32 = 0\r\nvar wg sync.WaitGroup\r\n\r\nfunc main() {\r\n\t// init a capacity of 18 goroutine pool with preallocing the space.\r\n\tpool, _ := grpool.NewPool(18, grpool.WithPreAlloc(true))\r\n\t// Release worker resource\r\n\tdefer pool.Release()\r\n\r\n\tfor i := 0; i \u003c 10; i++ {\r\n\t\twg.Add(1)\r\n\t\t_ = pool.Schedule(func() {\r\n\t\t\tprintFunc(i)\r\n\t\t})\r\n\t}\r\n\r\n\twg.Wait()\r\n\r\n\tfmt.Printf(\"running goroutines: %d\\n\", pool.Running())\r\n}\r\n\r\nfunc printFunc(i int) {\r\n\tatomic.AddInt32(\u0026count, 1)\r\n\tfmt.Println(\"Hello World! I am worker\" + strconv.Itoa(i) + \" from goroutine pool.\")\r\n\twg.Done()\r\n}\r\n```\r\n\r\n### Use non-blocking pool\r\n\r\n```go\r\npool, err := grpool.NewPool(1000, grpool.WithNonblocking(true))\r\n```\r\n\r\n\r\n### Customize panic handler\r\n\r\n```go\r\nfunc ph(v interface{}) {\r\n    // dosomething...\r\n\tfmt.Printf(\"[panic occurred]: %v\\n\", v)\r\n}\r\npool, err := grpool.NewPool(1000, grpool.WithPanicHandler(ph))\r\n```\r\n\r\n### Customize the time interval of clear stale worker\r\n\r\n```go\r\npool, err := grpool.NewPool(1000, grpool.WithExpiryDuration(time.Second * 5))\r\n```\r\n\r\n\r\n## License\r\n\r\n[MIT License](https://github.com/POABOB/grpool/blob/main/LICENSE)","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpoabob%2Fgrpool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpoabob%2Fgrpool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpoabob%2Fgrpool/lists"}