learn go defer

package main

// 参考文档:
//     https://github.com/Unknwon/the-way-to-go_ZH_CN/blob/master/eBook/06.4.md

import "fmt"

func main() {
    function1()
}

func function1() {
    fmt.Printf("In function1 at the top\n")
    defer function2()
    fmt.Printf("In function1 at the buttom\n")
}

func function2() {
    fmt.Printf("function2: Deferred until the end of the calling function!\n")
}

 

posted on 2015-11-22 17:33  zengjf  阅读(139)  评论(0)    收藏  举报

导航