{"id":27380140,"url":"https://github.com/mkch/sgo","last_synced_at":"2025-07-26T04:35:07.201Z","repository":{"id":287508733,"uuid":"964930279","full_name":"mkch/sgo","owner":"mkch","description":"Structured concurrency in go.","archived":false,"fork":false,"pushed_at":"2025-04-12T06:00:37.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-08T11:51:12.030Z","etag":null,"topics":["currency","golang","structed"],"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/mkch.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,"zenodo":null}},"created_at":"2025-04-12T03:50:03.000Z","updated_at":"2025-04-12T06:00:40.000Z","dependencies_parsed_at":"2025-04-12T06:32:04.857Z","dependency_job_id":"f25bfa5b-cc10-4205-81c9-69a24d514aec","html_url":"https://github.com/mkch/sgo","commit_stats":null,"previous_names":["mkch/sgo"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mkch/sgo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkch%2Fsgo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkch%2Fsgo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkch%2Fsgo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkch%2Fsgo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mkch","download_url":"https://codeload.github.com/mkch/sgo/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkch%2Fsgo/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267117516,"owners_count":24038675,"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-26T02:00:08.937Z","response_time":62,"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":["currency","golang","structed"],"created_at":"2025-04-13T14:19:16.166Z","updated_at":"2025-07-26T04:35:07.178Z","avatar_url":"https://github.com/mkch.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sgo\n\n[简体中文](README.zh-CN.md)\n\nsgo: Structured Concurrency Infrastructure for Go.\n\nsgo provides higher-level abstractions by encapsulating Go's concurrency primitives for common concurrent operations. Using sgo can significantly reduce the complexity of concurrent programming, thereby improving its efficiency and robustness.\n\n## Motivation\n\nThe design philosophy of sgo originates from [Notes on structured concurrency, or: Go statement considered harmful](https://vorpus.org/blog/notes-on-structured-concurrency-or-go-statement-considered-harmful/).\n\nThe article points out that using the `go` keyword directly for concurrent programming is as primitive and harmful as using `goto` statements for flow control in early FLOW-MATIC languages. This low-level concurrency control breaks code abstraction and hinders modular development and local reasoning. Just as structured programming replaced `goto` with sequence, selection, and loop constructs, structured concurrency requires high-level abstractions to replace direct use of `go`.\n\n## Basic Elements of Structured Concurrency\n\nBased on practical experience, Go's concurrency requirements can be categorized into three typical scenarios:\n\n1. Parallel execution and waiting\n\n    For example, executing multiple initialization tasks concurrently during program startup, then proceeding after all tasks complete.\n\n2. Parallel computation and result collection\n\n    For example, splitting a large array into slices for concurrent summation, then aggregating the results.\n\n3. Race execution and optimal selection\n\n    For example, querying multiple search engines concurrently and returning the first valid result.\n\nThese three requirements each have standard implementation patterns, but correctly and completely implementing them often requires:\n\n- Rich experience\n- Meticulous attention\n- Comprehensive testing\n\nReinventing these patterns each time places significant cognitive burden on developers. Following the \"structured concurrency\" philosophy, encapsulating these patterns into unified abstract structures can systematically solve these problems. sgo encapsulates the above three patterns as:\n\n1. sgo.Group\n\n    ```go\n    sgo.NewGroup().\n        Go(setupStep1).\n        Go(setupStep2).\n        Wait()\n    ```\n\n2. sgo.Collector\n\n    ```go\n    result := sgo.NewCollector[int]().\n        Go(func() int { return sumSlice(s[:99]) }).\n        Go(func() int { return sumSlice(s[99:]) }).\n        Collect()\n    sum := result[0] + result[1]\n    ```\n\n3. sgo.Racer\n\n    ```go\n    result := sgo.NewRacer[string](context.Background()).\n        Go(func(ctx context.Context) string {\n            return searchGoogle(ctx, keyword);\n        }).\n        Go(func(ctx context.Context) string {\n           return searchBing(ctx, keyword);\n        }).\n        Collect()\n    ```\n\n## Reflections on \"Structured Concurrency\"\n\nThe essence of structured concurrency lies in abstracting proven concurrent patterns into reusable programming components. This philosophy shares the same lineage as structured programming's transformation of `goto` statements into standard control structures. Its core value lies not in the implementation technology itself, but in the programming paradigm innovation it advocates.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmkch%2Fsgo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmkch%2Fsgo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmkch%2Fsgo/lists"}