On Wed, Sep 12, 2018 at 2:55 PM robert engels <reng...@ix.netcom.com> wrote:

> 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.
>

one has to be careful, yes. but it's not completely out of reach.

func Foo(a, b int) (int, error) { ... }

func Do() {
    var out = 0
    With(ctx, func() error {
        var err error
        out, err = Foo(42, 66)
        return err
    })
}

closures are great! (like fezzes and bowties, actually :P)

-s


>
> 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> wrote:
>
> Yes, you are correct. My bad :)
>
> On Sep 12, 2018, at 7:34 AM, Sebastien Binet <bi...@cern.ch> wrote:
>
>
>
> On Wed, Sep 12, 2018 at 2:23 PM robert engels <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.
> For more options, visit 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.
>

-- 
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.

Reply via email to