{"id":16032369,"url":"https://github.com/virtuald/go-oncectx","last_synced_at":"2025-10-18T09:46:43.605Z","repository":{"id":57572624,"uuid":"143906376","full_name":"virtuald/go-oncectx","owner":"virtuald","description":"A context-aware version of sync.Once","archived":false,"fork":false,"pushed_at":"2018-08-07T17:32:49.000Z","size":2,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-10T12:43:16.167Z","etag":null,"topics":["golang","sync"],"latest_commit_sha":null,"homepage":null,"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/virtuald.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}},"created_at":"2018-08-07T17:31:01.000Z","updated_at":"2018-10-11T18:29:07.000Z","dependencies_parsed_at":"2022-08-24T11:01:14.262Z","dependency_job_id":null,"html_url":"https://github.com/virtuald/go-oncectx","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/virtuald%2Fgo-oncectx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/virtuald%2Fgo-oncectx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/virtuald%2Fgo-oncectx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/virtuald%2Fgo-oncectx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/virtuald","download_url":"https://codeload.github.com/virtuald/go-oncectx/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247289398,"owners_count":20914464,"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":["golang","sync"],"created_at":"2024-10-08T21:21:48.695Z","updated_at":"2025-10-05T04:11:01.397Z","avatar_url":"https://github.com/virtuald.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"go-oncectx\n==========\n\nThis is a version of golang's `sync.Once` that allows calling `Do` with a\ncontext.\n\nIt is not expected that golang's stdlib will implement something like this, \nsee https://github.com/golang/go/issues/25312\n\nUsage is like the `sync.Once` package, except that you must pass `Do` a context.\nThe function called by the Do function is run in a separate goroutine and\nwill always run to completion, regardless of whether the context's Done\nchannel is closed. However, the Do function itself will return either when\nf returns or when the context Done channel is closed.\n\n\nWhy is this needed?\n-------------------\n\nA naive approach would do something like so:\n\n```\n\nfunc (o *Object) initSomething(ctx context.Context) {\n    o.once.Do(func() {\n      CallSomethingWithContext(ctx)  \n    })\n}\n\n```\n\nHowever, a careful reading will see that if you have multiple goroutines which\ncall `initSomething`, a cancellation of one of the caller's contexts will cause\ninitialization to fail for all callers, which is probably not an intuitive \nresult.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvirtuald%2Fgo-oncectx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvirtuald%2Fgo-oncectx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvirtuald%2Fgo-oncectx/lists"}