and then does mandatory cleanup at the end. It may look like this.
func doStuffAndCleanup() error {
doInitialization()
defer doCleanup() // doCleanup() must run no matter what.
if err := doStuff(); err != nil {
return err
}
return doCleanup()
}
Note that doCleanup() itself may fail and return an error.
doStuffAndCleanup() will call doCleanup() twice whenever there are no
errors. Calling doCleanup() twice is not optimal and may even break if
doCleanup() is not idempotent.
Is there any well known idiom in go for handling this sort of use case?
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.