Canonical guidance

Use when

Avoid

Preferred pattern

func sq(ctx context.Context, in <-chan int) <-chan int {
	out := make(chan int)
	go func() {
		defer close(out)
		for n := range in {
			select {
			case <-ctx.Done():
				return
			case out <- n * n:
			}
		}
	}()
	return out
}

Anti-pattern

Explanation: This anti-pattern is common because downstream consumers often drain everything in demos, but real callers frequently stop early and expose blocked senders.

Why

Related pages

Sources