Goroutine lifecycle
Every goroutine you start needs an owner and a way to end. Long-running work usually watches a context and returns when it is cancelled, so shutdown does not leave goroutines running or blocked forever.
Minimal example
for {
select {
case <-ctx.Done():
return
case <-t.C:
refresh(ctx)
}
}Learn this concept
Lesson 2.16 · Background refresh with atomic.PointerUsed in exercises
Exercise 2.17 · GET /v1/restaurants: open status Exercise 3.19 · API and notifier shutdown Exercise 5.3 · Per-user WebSocket hub Exercise 5.5 · Per-user order event bridgeRelatedatomic.Pointer