{"id":22741845,"url":"https://github.com/t2bot/go-singleflight-streams","last_synced_at":"2026-02-11T05:32:31.515Z","repository":{"id":172310435,"uuid":"648829783","full_name":"t2bot/go-singleflight-streams","owner":"t2bot","description":"Go library to return a dedicated reader to each singleflight consumer. Useful for reading a source once, but sharing the result with many consumers.","archived":false,"fork":false,"pushed_at":"2023-11-24T02:45:05.000Z","size":37,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-26T19:02:12.053Z","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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-06-02T23:41:46.000Z","updated_at":"2023-06-03T21:29:55.000Z","dependencies_parsed_at":"2023-11-24T03:28:36.656Z","dependency_job_id":"433693da-626b-4138-a646-79c975cfb8e7","html_url":"https://github.com/t2bot/go-singleflight-streams","commit_stats":null,"previous_names":["t2bot/go-singleflight-streams"],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/t2bot/go-singleflight-streams","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/t2bot%2Fgo-singleflight-streams","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/t2bot%2Fgo-singleflight-streams/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/t2bot%2Fgo-singleflight-streams/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/t2bot%2Fgo-singleflight-streams/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/t2bot","download_url":"https://codeload.github.com/t2bot/go-singleflight-streams/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/t2bot%2Fgo-singleflight-streams/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29327326,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-11T03:52:29.695Z","status":"ssl_error","status_checked_at":"2026-02-11T03:52:23.094Z","response_time":97,"last_error":"SSL_read: 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":[],"created_at":"2024-12-11T00:18:54.183Z","updated_at":"2026-02-11T05:32:31.499Z","avatar_url":"https://github.com/t2bot.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-singleflight-streams\nGo library to return a dedicated reader to each singleflight consumer. Useful for reading a source once, \nbut sharing the result with many consumers.\n\nExample usage ([Go Playground](https://go.dev/play/p/29wwkiHODU1)):\n\n```go\npackage main\n\nimport (\n\t\"bytes\"\n\t\"crypto/rand\"\n\t\"fmt\"\n\t\"io\"\n\t\"sync\"\n\t\"time\"\n\n\tsfstreams \"github.com/t2bot/go-singleflight-streams\"\n)\n\nfunc main() {\n\tg := new(sfstreams.Group)\n\n\tworkFn := func() (io.ReadCloser, error) {\n\t\t// Call your resource or otherwise create a stream. Here we create an\n\t\t// example stream made of random bytes.\n\t\tb := make([]byte, 16*1024) // 16kb\n\t\t_, err := rand.Read(b)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\ttime.Sleep(1 * time.Second) // for example purposes, we add a delay\n\t\treturn io.NopCloser(bytes.NewBuffer(b)), nil\n\t}\n\n\tkey := \"my_resource\" // deduplication key\n\n\t// This loop simulates multiple requests, such as incoming HTTP 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\t\n\t\t\t// `r` is guaranteed to be unique for this call\n\t\t\tr, err, shared := g.Do(key, workFn)\n\t\t\tif r != nil {\n\t\t\t\tdefer r.Close()\n\t\t\t}\n\t\t\tif err != nil {\n\t\t\t\tpanic(err) // or whatever other error handling\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 (to distinct readers).\n\t\t\t} else {\n\t\t\t\t// This shouldn't happen in this example\n\t\t\t\tfmt.Println(\"WARN: Response was not shared!\")\n\t\t\t}\n\n\t\t\t// We discard here, but a more realistic handling might be to stream\n\t\t\t// the response to a user.\n\t\t\tc, err := io.Copy(io.Discard, r)\n\t\t\tif err != nil {\n\t\t\t\tpanic(err) // or whatever other error handling\n\t\t\t}\n\n\t\t\tfmt.Println(\"Read bytes from stream: \", c)\n\t\t}()\n\t}\n\t\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-singleflight-streams","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ft2bot%2Fgo-singleflight-streams","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ft2bot%2Fgo-singleflight-streams/lists"}