19 延迟调用(Defer)
func foo() {
f, err := os.Open("myfile.txt")
if err != nil {
return
}
defer f.Close()
// ... lots of code
}func foo() {
mutex1.Lock()
mutex2.Lock()
defer func() {
mutex2.Unlock()
mutex1.Unlock()
}()
// ... more code
}最后更新于