Challenge 1 — Solution Task: Write a function countTo(ctx context.Context, n int) that counts from 1 to n, printing each number with a 300ms pause between them, but stops early and prints "Stopped early" if ctx is cancelled. Call it with a context.WithTimeout of 1 second and n = 10, so it stops before reaching 10. package main import ( "context" "fmt" "time" ) func countTo(ctx context.Context, n int) { for i := 1; i <= n; i++ { select { case <-ctx.Done(): fmt.Println("Stopped early") return case <-time.After(300 * time.Millisecond): fmt.Println(i) } } } func main() { ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second) defer cancel() countTo(ctx, 10) } Expected output: 1 2 3 Stopped early Notes: - Each loop iteration races ctx.Done() against a fresh 300ms timer — whichever fires first wins that iteration's select. - With a 1 second timeout and ~300ms per number, roughly 3 numbers print before the context's deadline is reached, at which point ctx.Done() fires and the function returns immediately via "Stopped early" rather than continuing to 10. - defer cancel() still runs even though the timeout (not a manual cancel) is what actually stopped the loop — calling cancel() after a timeout has already fired is harmless and simply releases the context's resources.