Re: [go-nuts] How to check if a request was cancelled

2017-11-08 Thread Glen Huang
In my case the client is the sole consumer of the context, so it should be fine. But I agree, checking error directly is more bullet-proof. I should probably form a habit adopting it. > On 8 Nov 2017, at 8:40 PM, Jakob Borg wrote: > > (expanding the code from the link) > > _, err := http.Defa

Re: [go-nuts] How to check if a request was cancelled

2017-11-08 Thread Jakob Borg
(expanding the code from the link) _, err := http.DefaultClient.Do(r) log.Println(err, ctx.Err() == context.Canceled) Note that, to be pedantic, this only tells you that the context has been cancelled - not that that was the error returned by the HTTP request. The HTTP request may have succeede

[go-nuts] How to check if a request was cancelled

2017-11-08 Thread Glen Huang
I have this simple code in which I try to check if the request was cancelled. But surprisingly, it prints false instead of true in go 1.9. I wonder what's the correct way to check that? package main import ( "context" "log" "net/http" ) func main() { r, _ := http.NewRequest("