Context.Done returns a channel that closes when a context is canceled or reaches its deadline. Reading from the channel then completes immediately, so concurrent code can detect expiration without comparing deadlines with the current time. section 10.6.1 section 10.6.3
Race a response against the deadline
Use select to let whichever event happens first control the function: return the backend response, or handle <-ctx.Done() when the context expires. The cancellation branch commonly returns the context’s error; newer Go code may use context.Cause(ctx) when cancellation has a specific cause. section 10.6.3

