{"id":27185844,"url":"https://github.com/inv2004/errchan","last_synced_at":"2025-06-13T17:32:24.624Z","repository":{"id":270165669,"uuid":"909505390","full_name":"inv2004/errchan","owner":"inv2004","description":"Make (golang) Channels Great Again","archived":false,"fork":false,"pushed_at":"2025-05-26T23:21:29.000Z","size":39,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-27T00:27:09.151Z","etag":null,"topics":[],"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/inv2004.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":"2024-12-28T22:47:59.000Z","updated_at":"2025-05-26T23:21:32.000Z","dependencies_parsed_at":"2025-04-09T17:55:17.948Z","dependency_job_id":"613881d0-93b5-47f6-b7f6-3881492356cd","html_url":"https://github.com/inv2004/errchan","commit_stats":null,"previous_names":["inv2004/errchan"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/inv2004/errchan","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inv2004%2Ferrchan","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inv2004%2Ferrchan/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inv2004%2Ferrchan/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inv2004%2Ferrchan/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/inv2004","download_url":"https://codeload.github.com/inv2004/errchan/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inv2004%2Ferrchan/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259688337,"owners_count":22896387,"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":[],"created_at":"2025-04-09T17:55:08.008Z","updated_at":"2025-06-13T17:32:24.590Z","avatar_url":"https://github.com/inv2004.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"Make (golang) Channels Great Again\n\n# `errchan.Chan`\n\nThe structure covers work with channels, context, cancellations and goroutine error-handling under the same hood\n\n# Documentation\nhttps://pkg.go.dev/github.com/inv2004/errchan\n\n# Motivation\nGolang channels are a powerful communication mechanism for goroutines. Unfortunately, there are some challenges in controlling, cancelling and handling errors using channels. \n\nThere are some helpers like https://pkg.go.dev/golang.org/x/sync/errgroup but the `errchan` mod also adds channels and context.\n\nThe main motivation is to have create a structure that can be returned as a channel from any function and takes care of all the stuff like creating, closing and error-control for the called goroutine, which can be difficult and tricky if you implement it using just basic types.\n\n# Example:\nhttps://go.dev/play/p/QktbZrM0CP0\n\n```go\npackage main\n\nimport (\n    \"context\"\n    \"errors\"\n    \"fmt\"\n\n    \"github.com/inv2004/errchan\"\n)\n\nfunc reader(ctx context.Context) *errchan.Chan[int] {\n    ech, ctx := errchan.WithContext[int](ctx, 10)\n\n    ech.Go(func(ch chan\u003c- int) error {\n        // ctx is unused here, because just one goroutine\n        for i := 1; i \u003c= 3; i++ {\n            ch \u003c- i\n        }\n        return errors.New(\"readerError\")\n    })\n\n  return ech\n}\n\nfunc writer(ech *errchan.Chan[int]) (int, error) {\n    cnt := 0\n    for x := range ech.Chan() {\n        cnt++\n        if x == 3 {\n            return cnt, errors.New(\"writerError\")\n        }\n    }\n\n    return cnt, nil\n}\n\nfunc main() {\n    ctx := context.Background()\n    ech := reader(ctx)\n    cnt, err := writer(ech)\n\n    fmt.Println(err)       // writerError\n    fmt.Println(cnt)       // 3\n    fmt.Println(ech.Err()) // readerError\n}\n```\n\n# TODO\n- Add `.SetLimit` to limit number of goroutines\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finv2004%2Ferrchan","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finv2004%2Ferrchan","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finv2004%2Ferrchan/lists"}