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. > On Sep 12, 2018, at 7:50 AM, robert engels <reng...@ix.netcom.com> wrote: > > Too early, and the coffee had not kicked in... > >> On Sep 12, 2018, at 7:49 AM, robert engels <reng...@ix.netcom.com >> <mailto:reng...@ix.netcom.com>> wrote: >> >> Yes, you are correct. My bad :) >> >>> On Sep 12, 2018, at 7:34 AM, Sebastien Binet <bi...@cern.ch >>> <mailto:bi...@cern.ch>> wrote: >>> >>> >>> >>> On Wed, Sep 12, 2018 at 2:23 PM robert engels <reng...@ix.netcom.com >>> <mailto:reng...@ix.netcom.com>> wrote: >>> 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. >>> >>> you just need to wrap it with a closure, just as Eric did: >>> >>> e.g.: >>> func QueryDB(a,b int) error { ... } >>> >>> WithContext(ctx, func() error { >>> return QueryDB(42, 666) >>> }) >>> >>> and voila. >>> >>> -s >> >> >> -- >> 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+unsubscr...@googlegroups.com >> <mailto:golang-nuts+unsubscr...@googlegroups.com>. >> For more options, visit https://groups.google.com/d/optout >> <https://groups.google.com/d/optout>. > -- 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+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.