Skip to content

Instantly share code, notes, and snippets.

@tomtsang
Created February 7, 2018 13:29
Show Gist options
  • Select an option

  • Save tomtsang/84c1274c7267685ef8b5ef08491ad1f6 to your computer and use it in GitHub Desktop.

Select an option

Save tomtsang/84c1274c7267685ef8b5ef08491ad1f6 to your computer and use it in GitHub Desktop.
golang-func-defer-2
package main
import "fmt"
func trace(s string) string {
fmt.Println("entering:", s)
return s
}
func un(s string) {
fmt.Println("leaving:", s)
}
func a() {
defer un(trace("a"))
fmt.Println("in a")
}
func b() {
defer un(trace("b"))
fmt.Println("in b")
a()
}
func main() {
b()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment