2
是否有可能defer
到外部函數的結束?Golang推遲對來電/外部功能進行操作?
// normal transaction
func dbStuff(){
db.Begin()
...
db.Commit()
}
// normal transaction w/ defer
func dbStuff(){
db.Begin()
defer db.Commit()
...
}
這可能嗎?
// can you defer to caller/outer function?
func dbStuff(){
db.Trans()
...
}
// will Commit() when dbStuff() returns
func (db Db) Trans(){
db.Begin()
defer db.Commit() // to caller/outer function
}