{"id":13809081,"url":"https://github.com/fatih/semgroup","last_synced_at":"2025-04-11T11:49:21.463Z","repository":{"id":42052940,"uuid":"466097262","full_name":"fatih/semgroup","owner":"fatih","description":"Like errgroup/waitgroup, but only runs a maximum of tasks at any time.","archived":false,"fork":false,"pushed_at":"2024-10-03T06:56:41.000Z","size":22,"stargazers_count":315,"open_issues_count":0,"forks_count":15,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-04-03T17:05:26.337Z","etag":null,"topics":["concurrency","errgroup","go","golang","semaphore","waitgroup"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/fatih/semgroup","language":"Go","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fatih.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-03-04T11:27:39.000Z","updated_at":"2025-02-28T01:29:48.000Z","dependencies_parsed_at":"2025-02-27T12:13:44.810Z","dependency_job_id":"9e52499b-d435-4c16-9a8e-57717d824af3","html_url":"https://github.com/fatih/semgroup","commit_stats":{"total_commits":10,"total_committers":5,"mean_commits":2.0,"dds":0.4,"last_synced_commit":"de404588ab3d4b4ca6f8afba200b5b74994879f8"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fatih%2Fsemgroup","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fatih%2Fsemgroup/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fatih%2Fsemgroup/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fatih%2Fsemgroup/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fatih","download_url":"https://codeload.github.com/fatih/semgroup/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248389136,"owners_count":21095525,"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","errgroup","go","golang","semaphore","waitgroup"],"created_at":"2024-08-04T01:02:01.053Z","updated_at":"2025-04-11T11:49:21.441Z","avatar_url":"https://github.com/fatih.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# semgroup [![](https://github.com/fatih/semgroup/workflows/build/badge.svg)](https://github.com/fatih/semgroup/actions) [![PkgGoDev](https://pkg.go.dev/badge/github.com/fatih/semgroup)](https://pkg.go.dev/github.com/fatih/semgroup)\n\nsemgroup provides synchronization and error propagation, for groups of goroutines working on subtasks of a common task. It uses a weighted semaphore implementation to make sure that only a number of maximum tasks can be run at any time.\n\nUnlike [golang.org/x/sync/errgroup](https://pkg.go.dev/golang.org/x/sync/errgroup), it doesn't return the first non-nil error, rather it accumulates all errors and returns a set of errors, allowing each task to fullfil their task. \n\n\n# Install\n\n```bash\ngo get github.com/fatih/semgroup\n```\n\n# Example\n\nWith no errors:\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\t\"github.com/fatih/semgroup\"\n)\n\nfunc main() {\n\tconst maxWorkers = 2\n\ts := semgroup.NewGroup(context.Background(), maxWorkers)\n\n\tvisitors := []int{5, 2, 10, 8, 9, 3, 1}\n\n\tfor _, v := range visitors {\n\t\tv := v\n\n\t\ts.Go(func() error {\n\t\t\tfmt.Println(\"Visits: \", v)\n\t\t\treturn nil\n\t\t})\n\t}\n\n\t// Wait for all visits to complete. Any errors are accumulated.\n\tif err := s.Wait(); err != nil {\n\t\tfmt.Println(err)\n\t}\n\n\t// Output:\n\t// Visits: 2\n\t// Visits: 10\n\t// Visits: 8\n\t// Visits: 9\n\t// Visits: 3\n\t// Visits: 1\n\t// Visits: 5\n}\n```\n\nWith errors:\n\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"errors\"\n\t\"fmt\"\n\n\t\"github.com/fatih/semgroup\"\n)\n\nfunc main() {\n\tconst maxWorkers = 2\n\ts := semgroup.NewGroup(context.Background(), maxWorkers)\n\n\tvisitors := []int{1, 1, 1, 1, 2, 2, 1, 1, 2}\n\n\tfor _, v := range visitors {\n\t\tv := v\n\n\t\ts.Go(func() error {\n\t\t\tif v != 1 {\n\t\t\t\treturn errors.New(\"only one visitor is allowed\")\n\t\t\t}\n\t\t\treturn nil\n\t\t})\n\t}\n\n\t// Wait for all visits to complete. Any errors are accumulated.\n\tif err := s.Wait(); err != nil {\n\t\tfmt.Println(err)\n\t}\n\n\t// Output:\n\t// 3 error(s) occurred:\n\t// * only one visitor is allowed\n\t// * only one visitor is allowed\n\t// * only one visitor is allowed\n}\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffatih%2Fsemgroup","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffatih%2Fsemgroup","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffatih%2Fsemgroup/lists"}