{"id":21616154,"url":"https://github.com/hsson/once","last_synced_at":"2025-04-11T07:33:46.155Z","repository":{"id":85431840,"uuid":"318911595","full_name":"hsson/once","owner":"hsson","description":"Drop-in replacement for Go's sync.Once with added features for returning values","archived":false,"fork":false,"pushed_at":"2022-10-25T16:05:14.000Z","size":7,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-25T05:05:25.776Z","etag":null,"topics":["mutex","once-do","sync","synchronization"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hsson.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}},"created_at":"2020-12-05T23:39:30.000Z","updated_at":"2023-11-14T09:32:13.000Z","dependencies_parsed_at":"2023-03-13T05:14:00.343Z","dependency_job_id":null,"html_url":"https://github.com/hsson/once","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hsson%2Fonce","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hsson%2Fonce/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hsson%2Fonce/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hsson%2Fonce/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hsson","download_url":"https://codeload.github.com/hsson/once/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248358843,"owners_count":21090442,"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":["mutex","once-do","sync","synchronization"],"created_at":"2024-11-24T22:13:50.157Z","updated_at":"2025-04-11T07:33:46.119Z","avatar_url":"https://github.com/hsson.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# hsson/once\n[![PkgGoDev](https://pkg.go.dev/badge/github.com/hsson/once)](https://pkg.go.dev/github.com/hsson/once) [![GoReportCard](https://goreportcard.com/badge/github.com/hsson/once)](https://goreportcard.com/report/github.com/hsson/once)\n\nA re-implementation and drop-in replacement of the standard  Go (Golang) `sync.Once`, with added support for return values (using generics)! This package exports three additional `Once`-like primitives, in addition to the standard `once.Once`:\n\n`once.Error` returns an error value\n```go\nDo(f func() error) error\n```\n`once.Value[T]` returns a value\n```go\nDo(f func() T) T\n```\n`once.ValueError[T]` returns a (value, error) tuple\n```go\nDo(f func() (T, error)) (T, error)\n```\n\nThese three primitives have the behavior that, like with the standard `Once`, the function passed is ever only executed once. However, they also return the value returned by that one execution to all subsequent callers.\n\n\n## Example usage\n```go\nvar o once.ValueError[string]\nval, err := o.Do(func() (string, error) {\n  return \"Hello!\", nil\n})\nif err != nil {\n  // Do something\n}\nfmt.Println(val) // prints \"Hello!\"\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhsson%2Fonce","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhsson%2Fonce","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhsson%2Fonce/lists"}