{"id":19770719,"url":"https://github.com/sunqirui1987/parallelsgo","last_synced_at":"2025-10-06T13:47:38.771Z","repository":{"id":146112399,"uuid":"218008446","full_name":"sunqirui1987/parallelsgo","owner":"sunqirui1987","description":"parallels exec go function","archived":false,"fork":false,"pushed_at":"2019-12-09T02:37:07.000Z","size":8,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-28T11:29:05.339Z","etag":null,"topics":["parallels"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sunqirui1987.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2019-10-28T09:16:53.000Z","updated_at":"2019-12-09T02:37:09.000Z","dependencies_parsed_at":"2023-05-15T23:15:33.297Z","dependency_job_id":null,"html_url":"https://github.com/sunqirui1987/parallelsgo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/sunqirui1987/parallelsgo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sunqirui1987%2Fparallelsgo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sunqirui1987%2Fparallelsgo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sunqirui1987%2Fparallelsgo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sunqirui1987%2Fparallelsgo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sunqirui1987","download_url":"https://codeload.github.com/sunqirui1987/parallelsgo/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sunqirui1987%2Fparallelsgo/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278621841,"owners_count":26017253,"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","status":"online","status_checked_at":"2025-10-06T02:00:05.630Z","response_time":65,"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":["parallels"],"created_at":"2024-11-12T04:49:37.347Z","updated_at":"2025-10-06T13:47:38.757Z","avatar_url":"https://github.com/sunqirui1987.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"#并行执行 GO函数\n\n\n```\nPackage parallelsgo provides synchronization, error propagation, and Context\nparallelsgo 包为一组子任务的 goroutine 提供了 goroutine 同步,错误取消功能.\n\nparallelsgo 包含三种常用方式\n\n1、直接使用 此时不会因为一个任务失败导致所有任务被 cancel:\n\t\tg := \u0026parallelsgo.Parallels{}\n\t\tg.Go(func(ctx context.Context, args interface{}) {\n\t\t\t// NOTE: 此时 ctx 为 context.Background()\n\t\t\t// do something\n\t\t},nil)\n\n2、WithContext 使用 WithContext 时不会因为一个任务失败导致所有任务被 cancel:\n\t\tg := parallelsgo.WithContext(ctx)\n\t\tg.Go(func(ctx context.Context, args interface{}) {\n\t\t\t// NOTE: 此时 ctx 为 parallelsgo.WithContext 传递的 ctx\n\t\t\t// do something\n\t\t},nil)\n\n3、WithCancel 使用 WithCancel 时如果有一个人任务失败会导致所有*未进行或进行中*的任务被 cancel:\n\t\tg := parallelsgo.WithCancel(ctx)\n\t\tg.Go(func(ctx context.Context, args interface{}) {\n\t\t\t// NOTE: 此时 ctx 是从 parallelsgo.WithContext 传递的 ctx 派生出的 ctx\n\t\t\t// do something\n\t\t},nil)\n\n设置最大并行数 GOMAXPROCS 对以上三种使用方式均起效\nNOTE: 由于 parallelsgo 实现问题,设定 GOMAXPROCS 的 parallelsgo 需要立即调用 Wait() 例如:\n\n\t\tg := parallelsgo.WithCancel(ctx)\n\t\tg.GOMAXPROCS(2)\n\t\t// task1\n\t\tg.Go(func(ctx context.Context, args interface{}) {\n\t\t\tfmt.Println(\"%v\", args)\n\t\t},\"task1\")\n\n\t\t// task2\n\t\tg.Go(func(ctx context.Context, args interface{}) {\n\t\t\tfmt.Println(\"%v\", args)\n\t\t},\"task2\")\n\n\t\t// task3\n\t\tg.Go(func(ctx context.Context, args interface{}) {\n\t\t\tfmt.Println(\"%v\", args)\n\t\t},\"task3\")\n\t\t\n\t\t// NOTE: 此时设置的 GOMAXPROCS 为2, 添加了三个任务 task1, task2, task3 此时 task3 是不会运行的!\n\t\t// 只有调用了 Wait task3 才有运行的机会\n\t\tg.Wait() // task3 运行\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsunqirui1987%2Fparallelsgo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsunqirui1987%2Fparallelsgo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsunqirui1987%2Fparallelsgo/lists"}