Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Go handles this type of situation nicely using deferred function calls:

"Go's defer statement schedules a function call (the deferred function) to be run immediately before the function executing the defer returns. It's an unusual but effective way to deal with situations such as resources that must be released regardless of which path a function takes to return. The canonical examples are unlocking a mutex or closing a file." http://golang.org/doc/effective_go.html#defer



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: