{"id":19261892,"url":"https://github.com/bzsome/chaogo","last_synced_at":"2026-05-16T04:48:59.818Z","repository":{"id":144211114,"uuid":"261927853","full_name":"bzsome/chaoGo","owner":"bzsome","description":"Golang 工具类：队列，线程池","archived":false,"fork":false,"pushed_at":"2020-05-07T03:50:42.000Z","size":7,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-05T10:12:16.811Z","etag":null,"topics":[],"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/bzsome.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":"2020-05-07T02:15:01.000Z","updated_at":"2021-06-18T09:16:14.000Z","dependencies_parsed_at":"2023-08-15T23:52:23.879Z","dependency_job_id":null,"html_url":"https://github.com/bzsome/chaoGo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bzsome%2FchaoGo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bzsome%2FchaoGo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bzsome%2FchaoGo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bzsome%2FchaoGo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bzsome","download_url":"https://codeload.github.com/bzsome/chaoGo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240364294,"owners_count":19789756,"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-11-09T19:28:46.528Z","updated_at":"2026-05-16T04:48:54.798Z","avatar_url":"https://github.com/bzsome.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/xxjwxc/gowp.svg?branch=master)](https://travis-ci.org/xxjwxc/gowp)\n[![Go Report Card](https://goreportcard.com/badge/github.com/bzsome/chaoGo)](https://goreportcard.com/report/github.com/bzsome/chaoGo)\n[![codecov](https://codecov.io/gh/xxjwxc/gowp/branch/master/graph/badge.svg)](https://codecov.io/gh/xxjwxc/gowp)\n[![GoDoc](https://godoc.org/github.com/bzsome/chaoGo?status.svg)](https://godoc.org/github.com/bzsome/chaoGo)\n[![Mentioned in Awesome Go](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go)\n\n## golang worker pool\n\n### [中文说明](README_cn.md)\n\n- Concurrency limiting goroutine pool. \n- Limits the concurrency of task execution, not the number of tasks queued. \n- Never blocks submitting tasks, no matter how many tasks are queued.\n- Support timeout\n- Support through security queues [queue](https://github.com/bzsometest/public/tree/master/myqueue)\n\n\n## Installation\n\nThe simplest way to install the library is to run:\n\n```\n$ go get github.com/bzsome/chaoGo\n```\n\n\n### Support the maximum number of tasks, put them in the workpool and wait for them to be completed\n\n## Example\n\n```\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\n\t\"github.com/bzsome/chaoGo/workpool\"\n)\n\nfunc main() {\n\twp := workpool.New(10)     // Set the maximum number of threads\n\tfor i := 0; i \u003c 20; i++ { // Open 20 requests \n\t\tii := i\n\t\twp.Do(func() error {\n\t\t\tfor j := 0; j \u003c 10; j++ { // 0-10 values per print\n\t\t\t\tfmt.Println(fmt.Sprintf(\"%v-\u003e\\t%v\", ii, j))\n\t\t\t\ttime.Sleep(1 * time.Second)\n\t\t\t}\n\t\t\t//time.Sleep(1 * time.Second)\n\t\t\treturn nil\n\t\t})\n\t}\n\n\twp.Wait()\n\tfmt.Println(\"down\")\n}\n\n```\n\n### Support for error return\n\n```\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\n\t\"github.com/bzsome/chaoGo/workpool\"\n)\n\nfunc main() {\n\twp := workpool.New(10)             // Set the maximum number of threads\n\tfor i := 0; i \u003c 20; i++ { \n\t\tii := i\n\t\twp.Do(func() error {\n\t\t\tfor j := 0; j \u003c 10; j++ { // 0-10 values per print\n\t\t\t\tfmt.Println(fmt.Sprintf(\"%v-\u003e\\t%v\", ii, j))\n\t\t\t\tif ii == 1 {\n\t\t\t\t\treturn errors.Cause(errors.New(\"my test err\")) // have err return\n\t\t\t\t}\n\t\t\t\ttime.Sleep(1 * time.Second)\n\t\t\t}\n\n\t\t\treturn nil\n\t\t})\n\t}\n\n\terr := wp.Wait()\n\tif err != nil {\n\t\tfmt.Println(err)\n\t}\n\tfmt.Println(\"down\")\n\t}\n```\n\n### Supporting judgement of completion (non-blocking)\n\n```\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\n\t\"github.com/bzsome/chaoGo/workpool\"\n)\n\nfunc main() {\n\twp := workpool.New(5)              // Set the maximum number of threads\n\tfor i := 0; i \u003c 10; i++ { \n\t\t//\tii := i\n\t\twp.Do(func() error {\n\t\t\tfor j := 0; j \u003c 5; j++ { \n\t\t\t\t//fmt.Println(fmt.Sprintf(\"%v-\u003e\\t%v\", ii, j))\n\t\t\t\ttime.Sleep(1 * time.Second)\n\t\t\t}\n\t\t\treturn nil\n\t\t})\n\n\t\tfmt.Println(wp.IsDone())\n\t}\n\twp.Wait()\n\tfmt.Println(wp.IsDone())\n\tfmt.Println(\"down\")\n}\n```\n\n### Support synchronous waiting for results\n\n```\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\n\t\"github.com/bzsome/chaoGo/workpool\"\n)\n\nfunc main() {\n\twp := workpool.New(5) // Set the maximum number of threads\n\tfor i := 0; i \u003c 10; i++ { \n\t\tii := i\n\t\twp.DoWait(func() error {\n\t\t\tfor j := 0; j \u003c 5; j++ { \n\t\t\t\tfmt.Println(fmt.Sprintf(\"%v-\u003e\\t%v\", ii, j))\n\t\t\t\t// if ii == 1 {\n\t\t\t\t// \treturn errors.New(\"my test err\")\n\t\t\t\t// }\n\t\t\t\ttime.Sleep(1 * time.Second)\n\t\t\t}\n\n\t\t\treturn nil\n\t\t\t//time.Sleep(1 * time.Second)\n\t\t\t//return errors.New(\"my test err\")\n\t\t})\n\t}\n\n\terr := wp.Wait()\n\tif err != nil {\n\t\tfmt.Println(err)\n\t}\n\tfmt.Println(\"down\")\n}\n```\n\n### Support timeout exit\n\n```\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\t\"time\"\n\t\"github.com/bzsome/chaoGo/workpool\"\n)\n\nfunc main() {\n\twp := workpool.New(5)              // Set the maximum number of threads\n\t\twp.SetTimeout(time.Millisecond) // set max timeout\n\tfor i := 0; i \u003c 10; i++ { \n\t\tii := i\n\t\twp.DoWait(func() error {\n\t\t\tfor j := 0; j \u003c 5; j++ {\n\t\t\t\tfmt.Println(fmt.Sprintf(\"%v-\u003e\\t%v\", ii, j))\n\t\t\t\ttime.Sleep(1 * time.Second)\n\t\t\t}\n\n\t\t\treturn nil\n\t\t})\n\t}\n\n\terr := wp.Wait()\n\tif err != nil {\n\t\tfmt.Println(err)\n\t}\n\tfmt.Println(\"down\")\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbzsome%2Fchaogo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbzsome%2Fchaogo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbzsome%2Fchaogo/lists"}