← All Exercises
Context with Timeout
intermediatego
Background
Context timeouts prevent hanging operations and enable graceful shutdown in Go services.
Problem
Create a context with timeout that cancels an operation if it exceeds the specified duration.
Input
A timeout duration
Output
A context that cancels on timeout
Sample tests
Sample 1
Input: 5 second timeout
Expected: cancels after 5s
Your solution
Learning objective
Learn context cancellation and deadline management