These are chat archives for gin-gonic/gin

15th
Oct 2016
Igor Tonky
@tonky
Oct 15 2016 15:57
i'm new to Go and gin, and maybe missed it: how do i cancel current gin.Context, to drop all spawned goroutines for given request? like the Go's Context.WithCancel() or something. looking at the source - gin.Context.Done() always returns nil, so i assume there's some other agreed way to do this?
Javier Provecho Fernandez
@javierprovecho
Oct 15 2016 17:26
@tonky you can use func (c *Context) IsAborted() bool and func (c *Context) Abort(), it will stop calling handlers from the handler chain. If you want to end the existing goroutine after calling c.Abort(), you must return the function itself.
Igor Tonky
@tonky
Oct 15 2016 18:11
@javierprovecho i see, thanks. is there any built-in channel that i can signal goroutine failure, like a timeout? i'm selecting on 'results' channel to get the first available value, and i want my 'timeout's to be instantly returned and handler to return as well, if all my goroutines caught errors. here's a code sample: https://gist.github.com/tonky/87dfce308d2577c54bf9d61de398b038
or am i doing it wrong?
Javier Provecho Fernandez
@javierprovecho
Oct 15 2016 18:27
@tonky maybe checking https://godoc.org/net/http#CloseNotifier? case <- c.Writer.CloseNotify(): (if http1 use only in POST, read link doc for more info)
Igor Tonky
@tonky
Oct 15 2016 18:38
@javierprovecho hmm, interesting, i'll have a read at it, thanks!