{"id":16683034,"url":"https://github.com/hlts2/singleflight","last_synced_at":"2025-06-20T14:36:18.815Z","repository":{"id":57598240,"uuid":"324271510","full_name":"hlts2/singleflight","owner":"hlts2","description":"singleflight provides a duplicate function call a suppression mechanism.","archived":false,"fork":false,"pushed_at":"2020-12-30T08:01:27.000Z","size":11,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-13T12:14:23.448Z","etag":null,"topics":["cache","go","golang","simplex-algorithm","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/hlts2.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}},"created_at":"2020-12-25T02:24:14.000Z","updated_at":"2021-01-16T18:07:12.000Z","dependencies_parsed_at":"2022-08-29T23:51:38.743Z","dependency_job_id":null,"html_url":"https://github.com/hlts2/singleflight","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/hlts2/singleflight","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hlts2%2Fsingleflight","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hlts2%2Fsingleflight/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hlts2%2Fsingleflight/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hlts2%2Fsingleflight/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hlts2","download_url":"https://codeload.github.com/hlts2/singleflight/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hlts2%2Fsingleflight/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260962727,"owners_count":23089470,"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":["cache","go","golang","simplex-algorithm","singleflight"],"created_at":"2024-10-12T14:10:07.430Z","updated_at":"2025-06-20T14:36:13.801Z","avatar_url":"https://github.com/hlts2.png","language":"Go","readme":"# singleflight\n\n[![GoDoc](https://godoc.org/github.com/hlts2/singleflight?status.svg)](http://godoc.org/github.com/hlts2/singleflight)\n\nsingleflight is simple golang singleflight library and provides a duplicate function call a suppression\n\n## Requirement\n\nGo 1.15\n\n## Installing\n\n```\ngo get github.com/hlts2/singleflight\n```\n\n## Example\n\n```go\nimport (\n    \"log\"\n    \"sync\"\n    \n    \"github.com/hlts2/singleflight\"\n)\n\nvar group = New()\n\nfunc callAPI(key string) (v interface{}, err error, shared bool) {\n    v, err, shared = group.Do(key, func() (resp interface{}, err error) {\n        // send api request\n        return\n    })\n    return\n}\n\nfunc main() {\n    var wg sync.WaitGroup\n    \n    for i := 0; i \u003c 100; i++ {\n        wg.Add(1)\n        go func() {\n            defer wg.Done()\n            v, err, shared := callAPI(\"UserListAPI\")\n            if err == nil {\n                log.Printf(\"response: %v\", v)\n                log.Printf(\"shared: %v\", shared)\n            }\n        }()\n    }\n}\n```\n\n## Performance\n\nThe following represents [sync/singleflight](https://github.com/golang/sync/tree/master/singleflight) and [hlts2/singleflight](https://github.com/hlts2/singleflight) performance.\nThe `total` is the number of accesses and the `shared` is the number of shared results.\n\n```\ngoos: linux\ngoarch: amd64\npkg: github.com/hlts2/singleflight\nBenchmark_hlts2_singleflight-7   \t12671460\t        96.4 ns/op\t      80 B/op\t       2 allocs/op\n--- BENCH: Benchmark_singleflight-7\n    singleflight_bench_test.go:30: singleflight total: 1 shared: 0\n    singleflight_bench_test.go:30: singleflight total: 100 shared: 99\n    singleflight_bench_test.go:30: singleflight total: 10000 shared: 9999\n    singleflight_bench_test.go:30: singleflight total: 1000000 shared: 999999\n    singleflight_bench_test.go:30: singleflight total: 12671460 shared: 12671459\nBenchmark_sync_singleflight-7    \t13313968\t       119 ns/op\t      11 B/op\t       0 allocs/op\n--- BENCH: Benchmark_sync_singleflight-7\n    singleflight_bench_test.go:53: singleflight total: 1 shared: 0\n    singleflight_bench_test.go:53: singleflight total: 100 shared: 0\n    singleflight_bench_test.go:53: singleflight total: 10000 shared: 3546\n    singleflight_bench_test.go:53: singleflight total: 1000000 shared: 897228\n    singleflight_bench_test.go:53: singleflight total: 13313968 shared: 11728991\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhlts2%2Fsingleflight","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhlts2%2Fsingleflight","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhlts2%2Fsingleflight/lists"}