Skip to content

Instantly share code, notes, and snippets.

@dacr
Last active February 3, 2026 20:26
Show Gist options
  • Select an option

  • Save dacr/feb632a77b93eda349d8797688f6450f to your computer and use it in GitHub Desktop.

Select an option

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/be93b781be2717ad9c5b6419c9875b9eca182fd6
/*?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 License Version 2.0 (https://www.apache.org/licenses/LICENSE-2.0.txt)
// 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