Re: [go-nuts] How to do a cleanup of context cancelling?

2023-03-19 Thread Brian Candler
I'm pretty sure that code won't code will compile as written. Firstly, http.DefaultClient.Do (req) returns two values, but c is a chan error. Secondly, the second case statement is invalid syntax (case err := f(<-c):) - you can't put a function call in here,

Re: [go-nuts] How to do a cleanup of context cancelling?

2023-03-18 Thread Jeevesh Juneja
Proabably should change code to: func httpDo(ctx context.Context, req \*http.Request, f func(\*http.Response, error) error) error { // Run the HTTP request in a goroutine and pass the response to f. c := make(chan error, 1) req = req.WithContext(ctx) go func() { c <- http.DefaultClient.Do(req)

Re: [go-nuts] How to do a cleanup of context cancelling?

2019-02-14 Thread Ian Lance Taylor
On Thu, Feb 14, 2019 at 2:13 AM Jingguo Yao wrote: > > https://blog.golang.org/context uses the following code to cancel the request > if ctx.Done is closed before the goroutine exits: > > func httpDo(ctx context.Context, req *http.Request, f func(*http.Response, > error) error) error { >