{"id":13413060,"url":"https://github.com/zenthangplus/go-workerpool","last_synced_at":"2026-01-18T04:25:44.363Z","repository":{"id":57706807,"uuid":"497475785","full_name":"zenthangplus/go-workerpool","owner":"zenthangplus","description":"Go WorkerPool aims to control heavy Go Routines","archived":false,"fork":false,"pushed_at":"2022-08-20T15:05:50.000Z","size":28,"stargazers_count":12,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-18T00:26:34.231Z","etag":null,"topics":["golang","goroutine","threadpool","workerpool"],"latest_commit_sha":null,"homepage":"","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/zenthangplus.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":"2022-05-29T02:57:22.000Z","updated_at":"2025-05-22T11:33:35.000Z","dependencies_parsed_at":"2022-09-26T21:20:26.956Z","dependency_job_id":null,"html_url":"https://github.com/zenthangplus/go-workerpool","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/zenthangplus/go-workerpool","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zenthangplus%2Fgo-workerpool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zenthangplus%2Fgo-workerpool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zenthangplus%2Fgo-workerpool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zenthangplus%2Fgo-workerpool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zenthangplus","download_url":"https://codeload.github.com/zenthangplus/go-workerpool/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zenthangplus%2Fgo-workerpool/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28529529,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-18T00:39:45.795Z","status":"online","status_checked_at":"2026-01-18T02:00:07.578Z","response_time":98,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["golang","goroutine","threadpool","workerpool"],"created_at":"2024-07-30T20:01:32.958Z","updated_at":"2026-01-18T04:25:44.348Z","avatar_url":"https://github.com/zenthangplus.png","language":"Go","readme":"# Golang Worker Pool\n\n[![run tests](https://github.com/zenthangplus/go-workerpool/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/zenthangplus/go-workerpool/actions/workflows/test.yml)\n[![codecov](https://codecov.io/gh/zenthangplus/go-workerpool/branch/main/graph/badge.svg)](https://codecov.io/gh/zenthangplus/go-workerpool)\n[![goreportcard](https://goreportcard.com/badge/github.com/zenthangplus/go-workerpool)](https://goreportcard.com/report/github.com/zenthangplus/go-workerpool)\n\nInspired from Java Thread Pool, Go WorkerPool aims to control heavy Go Routines.\n\n## Installation\n\nThe simplest way to install the library is to run:\n\n```shell\ngo get github.com/zenthangplus/go-workerpool\n```\n\n## Example\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/zenthangplus/go-workerpool\"\n)\n\nfunc main() {\n\t// Init worker pool with 3 workers to run concurrently.\n\tpool := workerpool.NewFixedSize(3)\n\n\t// Start worker pool\n\tpool.Start()\n\n\t// pool.Submit will block until slot available in Pool queue. \n\t// Submit an identifiable job, ID will be generated randomly (using UUID)\n\tpool.Submit(workerpool.NewIdentifiableJob(func() {\n\t\t// Do a heavy job\n\t}))\n\t// Use NewCustomIdentifierJob if you don't want ID to be generated randomly\n\tpool.Submit(workerpool.NewCustomIdentifierJob(\"custom-id\", func() { \n\t\t// Do a heavy job\n\t}))\n\t// or Submit a simple function without identifier\n\tpool.SubmitFunc(func() {// simpler way of: Submit(FuncJob(func() {})) \n\t\t// Do a heavy job\n\t})\n\n\t// pool.SubmitConfidently will submit a job in confident mode, \n\t// this function will return ErrPoolFull when Pool queue is full.\n\terr := pool.SubmitConfidently(workerpool.NewIdentifiableJob(func() {\n\t\t// Do a heavy job\n\t}))\n\tif err == workerpool.ErrPoolFull {\n\t\tfmt.Println(\"Pool is full\")\n\t}\n}\n```\n\n## Usage\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/zenthangplus/go-workerpool\"\n)\n\nfunc main() {\n\t// Initiate worker pool with fixed size. Eg: 3 workers to run concurrently.\n\tpool := workerpool.NewFixedSize(3)\n\n\t// Or initiate fixed size worker pool with custom options.\n\tpool = workerpool.NewFixedSize(3,\n\t\t// When you want to custom mode\n\t\tworkerpool.WithMode(workerpool.FixedSize),\n\t\t\n\t\t// When you want to custom number of workers\n\t\tworkerpool.WithNumberWorkers(5),\n\t\t\n\t\t// When you want to customize capacity\n\t\tworkerpool.WithCapacity(6),\n\t\t\n\t\t// When you want to custom log function\n\t\tworkerpool.WithLogFunc(func(msgFormat string, args ...interface{}) {\n\t\t\tfmt.Printf(msgFormat+\"\\n\", args...)\n\t\t}),\n\t)\n\n\t// Start worker pool\n\tpool.Start()\n\t\n\t// Init a functional job with ID is generated randomly\n\tjob1 := workerpool.NewIdentifiableJob(func() {})\n\n\t// init a functional job with predefined ID\n\tjob2 := workerpool.NewCustomIdentifierJob(\"test-an-id\", func() {})\n\n\t// Submit job in normal mode, it will block until pool has available slot.\n\tpool.Submit(job1)\n\t\n\t// or Submit a simple function\n\tpool.SubmitFunc(func() {})\n\t\n\t// Submit in confident mode, it will return ErrPoolFull when pool is full. \n\terr := pool.SubmitConfidently(job2)\n\tif err != nil {\n\t\tfmt.Print(err)\n\t}\n}\n\n// CompressDirJob\n// You can create a custom Job by implement `Job` interface\ntype CompressDirJob struct {\n\tdirectory string\n}\n\nfunc NewCompressDirJob(directory string) *CompressDirJob {\n\treturn \u0026CompressDirJob{directory: directory}\n}\n\nfunc (c CompressDirJob) Id() string {\n\treturn \"directory-\" + c.directory\n}\n\nfunc (c CompressDirJob) Exec() {\n\t// Do compress directory\n}\n```","funding_links":[],"categories":["Goroutines"],"sub_categories":["Search and Analytic Databases","检索及分析资料库"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzenthangplus%2Fgo-workerpool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzenthangplus%2Fgo-workerpool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzenthangplus%2Fgo-workerpool/lists"}