Created
February 7, 2018 13:29
-
-
Save tomtsang/84c1274c7267685ef8b5ef08491ad1f6 to your computer and use it in GitHub Desktop.
golang-func-defer-2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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