🐹 Go (Golang)
Intermediate
What is the context package and why is it important?
Answer
The context package provides a standard way to carry deadlines, cancellation signals, and request-scoped values across API boundaries and goroutines. A context.Context is passed as the first argument to functions that do I/O or long-running work: func FetchUser(ctx context.Context, id int) (*User, error). When a request times out or is cancelled upstream, the context is cancelled, and well-behaved functions propagate that cancellation immediately, freeing resources. Without context, a cancelled HTTP request would still cause downstream goroutines to keep running, wasting CPU and connections.