Challenge 2 — Solution Task: Using context.WithCancel, start a goroutine that prints "Working..." every 200ms until cancelled. In main, let it run for about 1 second, then call cancel() and confirm (via a short Sleep and a printed message) that the goroutine stopped. package main import ( "context" "fmt" "time" ) func worker(ctx context.Context) { for { select { case <-ctx.Done(): fmt.Println("Worker stopped") return case <-time.After(200 * time.Millisecond): fmt.Println("Working...") } } } func main() { ctx, cancel := context.WithCancel(context.Background()) go worker(ctx) time.Sleep(1 * time.Second) cancel() time.Sleep(300 * time.Millisecond) fmt.Println("Main confirms worker is done") } Expected output: Working... Working... Working... Working... Working... Worker stopped Main confirms worker is done Notes: - worker runs an infinite for loop (Fundamentals Chapter 4's "Shape 3"), only exiting via the ctx.Done() case inside select — there is no other way out of the loop. - cancel() is called manually here, not triggered by a timeout — this is the defining difference between WithCancel and WithTimeout from earlier in this chapter. - The final time.Sleep in main is a crude way to let the goroutine's "Worker stopped" message print before main() exits; real code would typically use a sync.WaitGroup (Intermediate Chapter 3) instead for a guaranteed wait.