Skip to main content

Go: Context With Timeout Helper

Go

Wrap a parent context with a deadline.

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