@@ -54,9 +54,10 @@ type Timer struct {
54
54
// Stop does not close the channel, to prevent a read from the channel succeeding
55
55
// incorrectly.
56
56
//
57
- // To prevent a timer created with NewTimer from firing after a call to Stop,
58
- // check the return value and drain the channel.
59
- // For example, assuming the program has not received from t.C already:
57
+ // Programs should handle the case in which the timer fires just as
58
+ // Stop is called by checking the return value.
59
+ // For example, if t.C needs to be drained before calling Reset and
60
+ // assuming the program has not received from t.C already:
60
61
//
61
62
// if !t.Stop() {
62
63
// <-t.C
@@ -97,10 +98,9 @@ func NewTimer(d Duration) *Timer {
97
98
// It returns true if the timer had been active, false if the timer had
98
99
// expired or been stopped.
99
100
//
100
- // Resetting a timer must take care not to race with the send into t.C
101
- // that happens when the current timer expires.
101
+ // Reset should always be invoked on stopped or expired timers with a drained channel.
102
102
// If a program has already received a value from t.C, the timer is known
103
- // to have expired, and t.Reset can be used directly.
103
+ // to have expired and the channel drained, so t.Reset can be used directly.
104
104
// If a program has not yet received a value from t.C, however,
105
105
// the timer must be stopped and—if Stop reports that the timer expired
106
106
// before being stopped—the channel explicitly drained:
0 commit comments