Canonical guidance

Use when

Avoid

Preferred pattern

timer := time.NewTimer(timeout)
defer timer.Stop()

select {
case <-done:
	return nil
case <-timer.C:
	return context.DeadlineExceeded
}

Anti-pattern

Explanation: This anti-pattern is tempting because it is short, but repeated one-shot timer creation obscures lifecycle costs and cancellation behavior.

Why

Related pages

Sources