{"id":37148942,"url":"https://github.com/jimmicro/singleflight","last_synced_at":"2026-01-14T17:35:35.560Z","repository":{"id":57693905,"uuid":"485824050","full_name":"jimmicro/singleflight","owner":"jimmicro","description":"go-zero/core/syncx/singleflight.go but with Go 1.18 generics","archived":false,"fork":false,"pushed_at":"2025-03-14T06:32:58.000Z","size":7,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-09T21:38:36.583Z","etag":null,"topics":["generic","go","singleflight"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jimmicro.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2022-04-26T14:35:08.000Z","updated_at":"2025-03-14T06:33:01.000Z","dependencies_parsed_at":"2025-08-09T21:38:38.742Z","dependency_job_id":"4d927ef8-0fa9-4309-b60d-a0f2ce39f141","html_url":"https://github.com/jimmicro/singleflight","commit_stats":null,"previous_names":["jimmicro/singleflight","jimyag/singleflight"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/jimmicro/singleflight","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jimmicro%2Fsingleflight","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jimmicro%2Fsingleflight/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jimmicro%2Fsingleflight/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jimmicro%2Fsingleflight/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jimmicro","download_url":"https://codeload.github.com/jimmicro/singleflight/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jimmicro%2Fsingleflight/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28428689,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T16:38:47.836Z","status":"ssl_error","status_checked_at":"2026-01-14T16:34:59.695Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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","go","singleflight"],"created_at":"2026-01-14T17:35:34.847Z","updated_at":"2026-01-14T17:35:35.539Z","avatar_url":"https://github.com/jimmicro.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# singleflight\n\nThis repo is a hard fork of [go-zero/singleflight.go at master · zeromicro/go-zero (github.com)](https://github.com/zeromicro/go-zero/blob/master/core/syncx/singleflight.go) that adds generics to the Group type so that there is no need for type assertion when using the library.\n\n## Install\n\n```shell\ngo get github.com/jimmicro/singleflight@latest\n```\n\n## Usage\n\n```go\npackage main\n\nimport (\n\t\"log\"\n\t\"sync\"\n\t\"sync/atomic\"\n\t\"time\"\n\n\t\"github.com/jimmicro/singleflight\"\n)\n\nfunc main() {\n\tg := singleflight.New[string]()\n\tc := make(chan string)\n\tvar calls int32\n\t// 给 calls 加 1\n\tfn := func() (string, error) {\n\t\tatomic.AddInt32(\u0026calls, 1)\n\t\treturn \u003c-c, nil\n\t}\n\n\tconst n = 10\n\tvar wg sync.WaitGroup\n\t// 同时加 1 最终的结果只能是 1\n\tfor i := 0; i \u003c n; i++ {\n\t\twg.Add(1)\n\t\tgo func() {\n\t\t\tv, err := g.Do(\"key\", fn)\n\t\t\tif err != nil {\n\t\t\t\tlog.Fatalf(\"Do error: %v\", err)\n\t\t\t}\n\t\t\tif v != \"bar\" {\n\t\t\t\tlog.Fatalf(\"got %q; want %q\", v, \"bar\")\n\t\t\t}\n\t\t\twg.Done()\n\t\t}()\n\t}\n\ttime.Sleep(100 * time.Millisecond) // let goroutines above block\n\tc \u003c- \"bar\"\n\twg.Wait()\n\tif got := atomic.LoadInt32(\u0026calls); got != 1 {\n\t\tlog.Fatalf(\"number of calls = %d; want 1\", got)\n\t}\n\tlog.Printf(\"done %v\", calls)\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjimmicro%2Fsingleflight","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjimmicro%2Fsingleflight","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjimmicro%2Fsingleflight/lists"}