{"id":22741820,"url":"https://github.com/t2bot/go-typed-singleflight","last_synced_at":"2026-01-11T02:24:44.995Z","repository":{"id":189613346,"uuid":"680965087","full_name":"t2bot/go-typed-singleflight","owner":"t2bot","description":"Generic-supporting golang.org/x/sync/singleflight","archived":false,"fork":false,"pushed_at":"2023-08-21T01:31:11.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-06T09:51:22.278Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/t2bot.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}},"created_at":"2023-08-21T00:54:56.000Z","updated_at":"2023-08-21T01:23:58.000Z","dependencies_parsed_at":"2023-08-21T02:26:47.287Z","dependency_job_id":"d80bd08e-7c80-4031-b405-a3983c6808fb","html_url":"https://github.com/t2bot/go-typed-singleflight","commit_stats":null,"previous_names":["t2bot/go-typed-singleflight"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/t2bot%2Fgo-typed-singleflight","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/t2bot%2Fgo-typed-singleflight/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/t2bot%2Fgo-typed-singleflight/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/t2bot%2Fgo-typed-singleflight/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/t2bot","download_url":"https://codeload.github.com/t2bot/go-typed-singleflight/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246423525,"owners_count":20774795,"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":"2024-12-11T00:18:03.820Z","updated_at":"2026-01-11T02:24:44.968Z","avatar_url":"https://github.com/t2bot.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-typed-singleflight\n\nGeneric-supporting [golang.org/x/sync/singleflight](https://golang.org/x/sync/singleflight).\n\nExample usage ([Go Playground](https://go.dev/play/p/jPDKiE7pNp_4)):\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"sync\"\n\t\"time\"\n\n\ttypedsf \"github.com/t2bot/go-typed-singleflight\"\n)\n\ntype MyValue string\n\nfunc main() {\n\tg := new(typedsf.Group[MyValue])\n\n\tworkFn := func() (MyValue, error) {\n\t\t// for example purposes only, sleep for a moment\n\t\ttime.Sleep(1 * time.Second)\n\t\treturn MyValue(\"this is a value\"), nil\n\t}\n\n\tkey := \"my_resource\" // deduplication key\n\n\t// This loop simulates multiple requests\n\twg := new(sync.WaitGroup)\n\tfor i := 0; i \u003c 5; i++ {\n\t\twg.Add(1)\n\t\tgo func() {\n\t\t\tdefer wg.Done()\n\t\t\tval, err, shared := g.Do(key, workFn)\n\t\t\tif err != nil {\n\t\t\t\tpanic(err)\n\t\t\t}\n\n\t\t\tif shared {\n\t\t\t\tfmt.Println(\"Response was shared!\")\n\t\t\t\t// When true, the workFn was only called once and its output used\n\t\t\t\t// multiple times.\n\t\t\t} else {\n\t\t\t\t// This might happen - it's dependent on the underlying singleflight\n\t\t\t\t// library behaviour.\n\t\t\t\tfmt.Println(\"WARN: Response was not shared!\")\n\t\t\t}\n\n\t\t\tfmt.Println(\"Got val: \", val)\n\t\t}()\n\t}\n\n\tfmt.Println(\"Waiting for all requests to finish\")\n\twg.Wait()\n\tfmt.Println(\"Done!\")\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ft2bot%2Fgo-typed-singleflight","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ft2bot%2Fgo-typed-singleflight","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ft2bot%2Fgo-typed-singleflight/lists"}