{"id":46767453,"url":"https://github.com/mix-go/xwp","last_synced_at":"2026-03-09T22:39:26.364Z","repository":{"id":53701982,"uuid":"349002363","full_name":"mix-go/xwp","owner":"mix-go","description":"A dynamic golang worker pool, coroutine pool / 通用动态工作池、协程池","archived":false,"fork":false,"pushed_at":"2023-08-25T06:19:24.000Z","size":23,"stargazers_count":17,"open_issues_count":0,"forks_count":7,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-19T10:13:33.509Z","etag":null,"topics":["golang","mixgo","worker-pool","workerpool","workpool","xwp"],"latest_commit_sha":null,"homepage":"https://openmix.org/mix-go","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mix-go.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":"2021-03-18T08:51:46.000Z","updated_at":"2023-08-10T02:42:13.000Z","dependencies_parsed_at":"2024-06-19T01:32:06.760Z","dependency_job_id":"aa55e2eb-6311-430d-9167-ffc5b6860166","html_url":"https://github.com/mix-go/xwp","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/mix-go/xwp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mix-go%2Fxwp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mix-go%2Fxwp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mix-go%2Fxwp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mix-go%2Fxwp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mix-go","download_url":"https://codeload.github.com/mix-go/xwp/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mix-go%2Fxwp/sbom","scorecard":{"id":650720,"data":{"date":"2025-08-11","repo":{"name":"github.com/mix-go/xwp","commit":"7c338e1be4669fd482f61c2dcb5fbf71a98f6112"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Code-Review","score":0,"reason":"Found 0/21 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: Apache License 2.0: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-21T13:27:00.884Z","repository_id":53701982,"created_at":"2025-08-21T13:27:00.884Z","updated_at":"2025-08-21T13:27:00.884Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30314780,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-09T20:05:46.299Z","status":"ssl_error","status_checked_at":"2026-03-09T19:57:04.425Z","response_time":61,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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","mixgo","worker-pool","workerpool","workpool","xwp"],"created_at":"2026-03-09T22:39:24.455Z","updated_at":"2026-03-09T22:39:25.981Z","avatar_url":"https://github.com/mix-go.png","language":"Go","readme":"\u003e OpenMix 出品：[https://openmix.org](https://openmix.org/mix-go)\n\n## Mix XWP\n\n通用动态工作池、协程池\n\nA dynamic golang worker pool, coroutine pool\n\n## Installation\n\n```\ngo get github.com/mix-go/xwp\n```\n\n## 单次调度\n\n\u003e 适合处理数据计算、转换等场景\n\n先创建一个结构体用来处理任务，使用类型断言转换任务数据类型，例如：`i := data.(int)` \n\n~~~go\ntype Foo struct {\n}\n\nfunc (t *Foo) Do(data interface{}) {\n    // do something\n}\n~~~\n\n调度任务\n\n- 也可以使用 `RunF` 采用闭包来处理任务\n- 如果不想阻塞执行，可以使用 `p.Start()` 启动\n\n~~~go\njobQueue := make(chan interface{}, 200)\np := \u0026xwp.WorkerPool{\n    JobQueue:       jobQueue,\n    MaxWorkers:     1000,\n    InitWorkers:    100,\n    MaxIdleWorkers: 100,\n    RunI:           \u0026Foo{},\n}\n\ngo func() {\n    // 投放任务\n    for i := 0; i \u003c 10000; i++ {\n        jobQueue \u003c- i\n    }\n\n    // 投放完停止调度\n    p.Stop()\n}()\n\np.Run() // 阻塞等待\n~~~\n\n## 常驻调度\n\n\u003e 适合处理 MQ 队列的异步消费\n\n以 Redis 作为 MQ 为例：\n\n~~~go\njobQueue := make(chan interface{}, 200)\np := \u0026xwp.WorkerPool{\n    JobQueue:       jobQueue,\n    MaxWorkers:     1000,\n    InitWorkers:    100,\n    MaxIdleWorkers: 100,\n    RunI:           \u0026Foo{},\n}\n\nch := make(chan os.Signal)\nsignal.Notify(ch, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM)\ngo func() {\n    \u003c-ch\n    p.Stop()\n}()\n\ngo func() {\n    for {\n        res, err := redis.BRPop(context.Background(), 3*time.Second, \"foo\").Result()\n        if err != nil {\n            if strings.Contains(err.Error(), \"redis: nil\") {\n                continue\n            }\n            fmt.Println(fmt.Sprintf(\"Redis Error: %s\", err))\n            p.Stop()\n            return\n        }\n        // brPop命令最后一个键才是值\n        jobQueue \u003c- res[1]\n    }\n}()\n\np.Run() // 阻塞等待\n~~~\n\n## 异常处理\n\n`Do` 方法中执行的代码，可能会出现 `panic` 异常，我们可以通过 `recover` 获取异常信息记录到日志或者执行其他处理\n\n~~~go\nfunc (t *Foo) Do(data interface{}) {\n    defer func() {\n        if err := recover(); err != nil {\n            // handle error\n        }\n    }()\n    // do something\n}\n~~~\n\n## 执行状态\n\n`Stats()` 可以返回 `Workers` 实时执行状态，通常可以使用一个定时器，定时打印或者告警处理\n\n```go\ngo func() {\n    ticker := time.NewTicker(1000 * time.Millisecond)\n    for {\n        \u003c-ticker.C\n        log.Printf(\"%+v\", p.Stats()) // 2021/04/26 14:32:53 \u0026{Active:5 Idle:95 Total:100}\n    }\n}()\n```\n\n## License\n\nApache License Version 2.0, http://www.apache.org/licenses/\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmix-go%2Fxwp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmix-go%2Fxwp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmix-go%2Fxwp/lists"}