Skip to content

Instantly share code, notes, and snippets.

@dacr
Created March 28, 2025 09:02
Show Gist options
  • Save dacr/feb632a77b93eda349d8797688f6450f to your computer and use it in GitHub Desktop.
Save dacr/feb632a77b93eda349d8797688f6450f to your computer and use it in GitHub Desktop.
go routines singleton / published by https://github.com/dacr/code-examples-manager #bf57f6e8-ddad-427b-99bd-e5027c56e9db/a88dba1529163054bf2e0c4890f2de7a207e1246
/*?sr/bin/true; exec /usr/bin/env nix-shell -p go --run "go run $0" #*/
// summary : go routines singleton
// keywords : go, goroutines, singleton, @testable
// publish : gist
// authors : David Crosson
// license : Apache NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2)
// id : bf57f6e8-ddad-427b-99bd-e5027c56e9db
// created-on : 2025-03-27T14:28:34+01:00
// managed-by : https://github.com/dacr/code-examples-manager
// run-with : nix-shell -p go --run "go run $file"
package main
import "sync"
var initialized int
var mySingleton sync.Once
func main() {
mySingleton.Do(func() {
initialized = 1
})
println(initialized)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment