{"id":22093108,"url":"https://github.com/orlovm/resultgroup","last_synced_at":"2025-07-29T07:31:55.577Z","repository":{"id":149512791,"uuid":"621734320","full_name":"orlovm/resultgroup","owner":"orlovm","description":"A lightweight library for handling results and errors from concurrent tasks, with optional error thresholds and context cancellation.","archived":false,"fork":false,"pushed_at":"2023-04-03T11:47:34.000Z","size":13,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-01T16:35:47.178Z","etag":null,"topics":["concurrency","errgroup","golang"],"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/orlovm.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":"2023-03-31T09:16:25.000Z","updated_at":"2023-06-29T12:32:47.000Z","dependencies_parsed_at":null,"dependency_job_id":"0894dc2a-bfdb-4589-8396-23ae396054dc","html_url":"https://github.com/orlovm/resultgroup","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/orlovm/resultgroup","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orlovm%2Fresultgroup","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orlovm%2Fresultgroup/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orlovm%2Fresultgroup/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orlovm%2Fresultgroup/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/orlovm","download_url":"https://codeload.github.com/orlovm/resultgroup/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orlovm%2Fresultgroup/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267645958,"owners_count":24120902,"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-07-29T02:00:12.549Z","response_time":2574,"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":["concurrency","errgroup","golang"],"created_at":"2024-12-01T03:12:36.075Z","updated_at":"2025-07-29T07:31:55.299Z","avatar_url":"https://github.com/orlovm.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# resultGroup\n\n[![CI](https://github.com/orlovm/resultgroup/actions/workflows/go.yml/badge.svg)](https://github.com/orlovm/resultgroup/actions/workflows/go.yml)\n[![codebeat badge](https://codebeat.co/badges/712c7ef7-4ac9-4df9-96b0-bd5c2d547e30)](https://codebeat.co/projects/github-com-orlovm-resultgroup-main)\n[![GitHub release](https://img.shields.io/github/release/orlovm/resultgroup.svg?label=version)](https://github.com/orlovm/resultgroup/releases/latest)  \n\nresultGroup is a simple and flexible Go library for managing the results and errors of concurrent tasks. It is inspired by the beloved HashiCorp's [go-multierror/Group](https://github.com/hashicorp/go-multierror/blob/master/group.go).\n\n## Motivation\n\nThe need to aggregate results from multiple sources is a common requirement in many applications. While libraries such as [errgroup](https://pkg.go.dev/golang.org/x/sync/errgroup) and [go-multierror](https://github.com/hashicorp/go-multierror/blob/master/group.go) can be used for this purpose, they often require additional boilerplate code and the use of mutexes or channels for synchronization. Result Group aims to streamline this process by offering a generic solution that minimizes boilerplate and simplifies the management of concurrent tasks.\n\n\n## Usage \n  \n\u003e **Note**\n\u003e ResultGroup works with Go 1.20 and is compatible with Go 1.20 wrapped errors.    \n  \nTo use Result Group, follow these steps:\n\n1. Import the package:\n\n```go\nimport \"github.com/orlovm/resultgroup\"\n```\n\n2. Create a new Result Group:\n\n```go\ngroup := resultgroup.Group[ResultType]{}\n```\n\nReplace `ResultType` with the type of the results you expect to collect.\n\n3. Alternatively, create a new Result Group with an error threshold:\n\n```go\nctx := context.Background()\nthreshold := 1\ngroup, ctx := resultgroup.WithErrorsThreshold[ResultType](ctx, threshold)\n```\n\n4. Run concurrent tasks using the `Go` method:\n\n```go\ngroup.Go(func() ([]ResultType, error) {\n    // Your concurrent task logic here\n})\n```\n\n5. Wait for all tasks to complete and collect the results:\n\n```go\nresults, err := group.Wait()\n```\n\n`err` could be used as usual go 1.20 wrapped error, or be easily unwrapped with `Unwrap() []error`\n\nHere's a complete example that demonstrates how to use Result Group to fetch data from multiple sources concurrently:\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\t\"github.com/orlovm/resultgroup\"\n)\n\ntype Data struct {\n\tSource string\n\tValue  int\n}\n\nfunc fetchData(source string) ([]Data, error) {\n\t// Simulate fetching data from the source\n\tdata := []Data{\n\t\t{Source: source, Value: 1},\n\t\t{Source: source, Value: 2},\n\t}\n\n\treturn data, nil\n}\n\nfunc main() {\n\tsources := []string{\"source1\", \"source2\", \"source3\"}\n\n\tctx := context.Background()\n\tgroup, _ := resultgroup.WithErrorsThreshold[Data](ctx, 1)\n\n\tfor _, source := range sources {\n\t\tsource := source\n\t\tgroup.Go(func() ([]Data, error) {\n\t\t\treturn fetchData(source)\n\t\t})\n\t}\n\n\tresults, err := group.Wait()\n\tif err != nil {\n\t\tfmt.Println(\"Error:\", err)\n                fmt.Println(\"Wrapped errors\", err.Unwrap())\n\t}\n\n\tfor _, result := range results {\n\t\tfmt.Printf(\"Source: %s, Value: %d\\n\", result.Source, result.Value)\n\t}\n}\n```  \n\nSee [tests](https://github.com/orlovm/resultgroup/blob/main/group_test.go) for more examples.\n## License\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Forlovm%2Fresultgroup","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Forlovm%2Fresultgroup","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Forlovm%2Fresultgroup/lists"}