{"id":20817365,"url":"https://github.com/golang-infrastructure/go-singleflight","last_synced_at":"2025-10-10T16:45:04.703Z","repository":{"id":120128538,"uuid":"569344403","full_name":"golang-infrastructure/go-singleflight","owner":"golang-infrastructure","description":"generic version of singleflight","archived":false,"fork":false,"pushed_at":"2022-11-22T17:16:22.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-12T05:43:16.260Z","etag":null,"topics":["generic","golang","singleflight"],"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/golang-infrastructure.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-11-22T16:03:02.000Z","updated_at":"2022-11-22T17:03:35.000Z","dependencies_parsed_at":"2024-06-21T04:07:05.687Z","dependency_job_id":"3727d907-19e1-4992-a29a-38da6f53c431","html_url":"https://github.com/golang-infrastructure/go-singleflight","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/golang-infrastructure/go-singleflight","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/golang-infrastructure%2Fgo-singleflight","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/golang-infrastructure%2Fgo-singleflight/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/golang-infrastructure%2Fgo-singleflight/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/golang-infrastructure%2Fgo-singleflight/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/golang-infrastructure","download_url":"https://codeload.github.com/golang-infrastructure/go-singleflight/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/golang-infrastructure%2Fgo-singleflight/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279004705,"owners_count":26083751,"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-10T02:00:06.843Z","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":["generic","golang","singleflight"],"created_at":"2024-11-17T21:41:18.778Z","updated_at":"2025-10-10T16:45:04.685Z","avatar_url":"https://github.com/golang-infrastructure.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go singleflight 泛型版\n\n# 一、这是啥\n\nGo官方扩展库singleflight的泛型实现：\n\n```text\nhttps://cs.opensource.google/go/x/sync\n```\n\n\n\n# 二、安装\n\n```bash\ngo get -u github.com/golang-infrastructure/go-singleflight\n```\n\n\n\n# 三、Example\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/golang-infrastructure/go-singleflight\"\n\t\"math/rand\"\n\t\"sync\"\n\t\"time\"\n)\n\nfunc main() {\n\n\tvar wg sync.WaitGroup\n\tg := singleflight.Group[int]{}\n\n\tbegin := time.Now()\n\tfor i := 0; i \u003c 10; i++ {\n\t\tid := i\n\t\twg.Add(1)\n\t\tgo func() {\n\t\t\tdefer wg.Done()\n\t\t\tv, err, shared := g.Do(\"test\", func() (value int, err error) {\n\t\t\t\tfmt.Println(id, \"开始执行了...\")\n\t\t\t\ttime.Sleep(time.Second * 3)\n\t\t\t\treturn rand.Intn(100), nil\n\t\t\t})\n\t\t\tfmt.Println(id, v, err, shared)\n\t\t}()\n\t}\n\twg.Wait()\n\tfmt.Println(\"cost: \", time.Now().Sub(begin).String())\n\tfmt.Println(\"All done\")\n}\n```\n\n\n\n# 四、TODO\n\n- 写篇文章讨论一下singleflight，分析一下源码\n- 跑下benchmark，看下泛型版对性能到底有多大的影响 \n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgolang-infrastructure%2Fgo-singleflight","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgolang-infrastructure%2Fgo-singleflight","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgolang-infrastructure%2Fgo-singleflight/lists"}