--
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...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/9adc5736-37da-4823-abc8-78f202171a15n%40googlegroups.com.
Thank you for your answer.Yes I understand the difference between the 2 functions.Can we say it's a best practice to use return context.Cause(ctx) instead of return ctx.Err() ?
Is there a reason to use return ctx.Err() instead of return context.Cause(ctx) ?
--Le samedi 4 avril 2026 à 06:17:24 UTC+2, Axel Wagner a écrit :The latter. ctx.Err() can only return the context-specific errors, while context.Cause can also return the error passed using WithCancelCause.On Fri, 3 Apr 2026 at 19:43, Pierre Durand <pierre...@gmail.com> wrote:My code has a select with a case that waits for context cancellation.Currently I'm doing this:case <-ctx.Done():
return ctx.Err()I noticed that some libraries and the stdlib are doing this:case <-ctx.Done():
return context.Cause(ctx)What is the best practice ?--
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...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/9adc5736-37da-4823-abc8-78f202171a15n%40googlegroups.com.
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...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/60b48394-4925-4fa6-8453-5445326eee37n%40googlegroups.com.