{"id":17330424,"url":"https://github.com/lxzan/concurrency","last_synced_at":"2025-04-14T17:31:10.609Z","repository":{"id":64535360,"uuid":"576184150","full_name":"lxzan/concurrency","owner":"lxzan","description":"通用型任务队列, 带并发控制和故障恢复","archived":false,"fork":false,"pushed_at":"2024-01-15T03:14:29.000Z","size":82,"stargazers_count":23,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-01T05:32:47.618Z","etag":null,"topics":["concurrency-control","goroutine-pool","task","taskqueue"],"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/lxzan.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":"2022-12-09T07:50:55.000Z","updated_at":"2024-10-02T15:46:55.000Z","dependencies_parsed_at":"2023-12-14T04:27:58.845Z","dependency_job_id":"dc453740-0ac0-4ff1-8d2e-de1789043d95","html_url":"https://github.com/lxzan/concurrency","commit_stats":{"total_commits":54,"total_committers":2,"mean_commits":27.0,"dds":"0.16666666666666663","last_synced_commit":"d4f4a15552d8a171e522390aac6dc57441613300"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lxzan%2Fconcurrency","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lxzan%2Fconcurrency/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lxzan%2Fconcurrency/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lxzan%2Fconcurrency/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lxzan","download_url":"https://codeload.github.com/lxzan/concurrency/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223639403,"owners_count":17177816,"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":["concurrency-control","goroutine-pool","task","taskqueue"],"created_at":"2024-10-15T14:51:14.545Z","updated_at":"2024-11-08T06:03:46.841Z","avatar_url":"https://github.com/lxzan.png","language":"Go","readme":"## Concurrency\n\n[![Build Status](https://github.com/lxzan/concurrency/workflows/Go%20Test/badge.svg?branch=master)](https://github.com/lxzan/concurrency/actions?query=branch%3Amaster) [![Coverage Statusd][1]][2]\n\n[1]: https://codecov.io/gh/lxzan/concurrency/branch/master/graph/badge.svg\n[2]: https://codecov.io/gh/lxzan/concurrency\n\n### Install\n\n```bash\ngo get -v github.com/lxzan/concurrency@latest\n```\n\n#### Usage\n\n##### 任务组\n\u003e 添加一组任务, 等待它们全部执行完成\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/lxzan/concurrency/groups\"\n\t\"sync/atomic\"\n)\n\nfunc main() {\n\tsum := int64(0)\n\tw := groups.New[int64]()\n\tfor i := int64(1); i \u003c= 10; i++ {\n\t\tw.Push(i)\n\t}\n\tw.OnMessage = func(args int64) error {\n\t\tfmt.Printf(\"%v \", args)\n\t\tatomic.AddInt64(\u0026sum, args)\n\t\treturn nil\n\t}\n\tw.Start()\n\tfmt.Printf(\"sum=%d\\n\", sum)\n}\n```\n\n```\n4 5 6 7 8 9 10 1 3 2 sum=55\n```\n\n##### 任务队列\n\u003e 把任务加入队列, 异步执行\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"github.com/lxzan/concurrency/queues\"\n\t\"sync/atomic\"\n)\n\nfunc main() {\n\tsum := int64(0)\n\tw := queues.New()\n\tfor i := int64(1); i \u003c= 10; i++ {\n\t\tvar x = i\n\t\tw.Push(func() {\n\t\t\tfmt.Printf(\"%v \", x)\n\t\t\tatomic.AddInt64(\u0026sum, x)\n\t\t})\n\t}\n\tw.Stop(context.Background())\n\tfmt.Printf(\"sum=%d\\n\", sum)\n}\n```\n\n```\n3 9 10 4 1 6 8 5 2 7 sum=55\n```\n\n### Benchmark\n\n```\ngo test -benchmem -run=^$ -bench . github.com/lxzan/concurrency/benchmark\ngoos: linux\ngoarch: amd64\npkg: github.com/lxzan/concurrency/benchmark\ncpu: AMD Ryzen 5 PRO 4650G with Radeon Graphics\nBenchmark_Fib-12                 1000000              1146 ns/op               0 B/op          0 allocs/op\nBenchmark_StdGo-12                  3661            317905 ns/op           16064 B/op       1001 allocs/op\nBenchmark_QueuesSingle-12           2178            532224 ns/op           67941 B/op       1098 allocs/op\nBenchmark_QueuesMultiple-12         3691            317757 ns/op           61648 B/op       1256 allocs/op\nBenchmark_Ants-12                   1569            751802 ns/op           22596 B/op       1097 allocs/op\nBenchmark_GoPool-12                 2910            406935 ns/op           19042 B/op       1093 allocs/op\nPASS\nok      github.com/lxzan/concurrency/benchmark  7.271s\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flxzan%2Fconcurrency","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flxzan%2Fconcurrency","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flxzan%2Fconcurrency/lists"}