--
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 golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
I think it would be problematic, as the callee signature is limited - func() error - and with lack of method overloading you will need a lot of WithXXXX methods…
func WithContext(context Context, f func() error) error {context.__entry__()defer context.__exit__()return f()}
I am pretty sure that is not correct, I am referring to:func WithContext(context Context, f func() error) error {context.__entry__()defer context.__exit__()return f()}You will need a lot of WithContext methods - based on the different signatures of function f.See the main method… I am assuming this is attempting to be a general facility - and thus the signature of f will vary.
Ok, now the coffee has kicked in, and it still has problems, because you cannot call a method and use a return value other than error without multiple signatures, unless you move all of the return values outside of the closure - like his example does with var a.
This would be extremely tedious (and probably error prone) to use IMO, especially with Go’s multiple return values.
Are closures, like the one in the main method idiomatic?
Thanks again. I think some of the use cases, especially those which implement some kind of finally (which includes locking use case) may just be implemented with simple functions. At least throwing exceptions is a rare event in Golang (panicking is what I meant with rare).
Are closures, like the one in the main method idiomatic?