Skip to main content

Go: Context With Timeout Helper

Go

Wrap a parent context with a deadline.

F
Fatima Al-Rashid Sample
Sample Oct 12, 2026
Go · 3 lines
1
2
3
func withTimeout(parent context.Context, d time.Duration) (context.Context, context.CancelFunc) {
	return context.WithTimeout(parent, d)
}
6 Fire 1 Learned something 0 Saved me time 1 Mind-blown
Sign in to react and star