Skip to content

Instantly share code, notes, and snippets.

@ehfeng
Created February 27, 2023 03:43
Show Gist options
  • Save ehfeng/4839fbe7022fcfd6ca8725389263df39 to your computer and use it in GitHub Desktop.
Save ehfeng/4839fbe7022fcfd6ca8725389263df39 to your computer and use it in GitHub Desktop.
func main() {
m := map[string]int{
"one": 1,
}
defer func() {
fmt.Println("deferred first", m)
}()
// a function will evaluate upon defer
// an expression evaluates immediately
defer fmt.Println("deferred second", m)
m = map[string]int{
"one": 2,
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment