Re: [go-nuts] Cancelling a server routine

2017-03-21 Thread Peter Bourgon
// establish the net.UDPConn and context.Context here. go func() { for { if err := conn.Read(p); err != nil { return } // do something with p } }() go func() { <-ctx.Done() conn.Close() // will interrupt the above goroutine with an error ret

[go-nuts] Cancelling a server routine

2017-03-21 Thread Florian Forster
Hi Go nuts, I have a (server) function that gets a context.Context and *listens* on a net.UDPConn. I would like this function to receive and handle network packets, but close the socket and return as soon as the context is cancelled. Ideally, I'd like to do something along these lines: for {