Skip to content

Instantly share code, notes, and snippets.

@yumed15
Created November 22, 2023 12:16
Show Gist options
  • Save yumed15/7f0b4ed3c7f7992c87e7d3d1ca068148 to your computer and use it in GitHub Desktop.
Save yumed15/7f0b4ed3c7f7992c87e7d3d1ca068148 to your computer and use it in GitHub Desktop.
var count int
increment := func() {count++}
decrement := func() {count--}
var once sync.Once
once.Do(increment)
once.Do(decrement)
fmt.Println(count) // 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment