Documentation
¶
Overview ¶
Package timeafter provides an analysis.Analyzer that reports timer ceremony a channel receive can replace.
One check: a time.NewTimer whose only uses are at most a deferred Stop and a single <-timer.C receive in a select sharing the declaration's statement list can be replaced by time.After in the receive. Since Go 1.23 the collector reclaims unreferenced timers before they fire, so the historical leak that justified the ceremony is gone. Statements may run between the declaration and the select; moving the deadline into the receive starts it later, which is the author's call. A timer that is Stopped conditionally, Reset, or received elsewhere is a real timer and is left alone, as is a select nested deeper than the declaration — inside a loop, most commonly — where time.After would restart the deadline every iteration. Only the timer := time.NewTimer(d) form is examined.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Analyzer = &analysis.Analyzer{
Name: "timeafter",
Doc: "reports timer ceremony that can be replaced by time.After",
Run: run,
}
Functions ¶
This section is empty.
Types ¶
This section is empty.