Say I have: func DoSomething(ctx context.Context) { for { select { case <- ctx.Done(): return case <- time.After(time.Second) // do something } } }
Based on the documentation of context: Successive calls to Done return the same value. So for each context there is only one channel, which is returned to every caller. Now given receiving on a closed channel never returns, above is not safe. I can check inside my second case if ctx.Err() is non nil, but its not a very clean solution. What would be safe way to use context.Done()? Or am I not understanding something right? -- 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.