From 48b739caacaf8e63b5c420218704b6ce58eac0af Mon Sep 17 00:00:00 2001 From: Shenghou Ma Date: Thu, 8 Nov 2012 23:25:48 +0800 Subject: [PATCH] time: clarify why timer.Stop and ticker.Stop don't close the channel R=golang-dev, r CC=golang-dev https://golang.org/cl/6818106 --- src/pkg/time/sleep.go | 2 ++ src/pkg/time/tick.go | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/pkg/time/sleep.go b/src/pkg/time/sleep.go index 27820b0eaa..657e254103 100644 --- a/src/pkg/time/sleep.go +++ b/src/pkg/time/sleep.go @@ -36,6 +36,8 @@ type Timer struct { // Stop prevents the Timer from firing. // It returns true if the call stops the timer, false if the timer has already // expired or stopped. +// Stop does not close the channel, to prevent a read from the channel succeeding +// incorrectly. func (t *Timer) Stop() (ok bool) { return stopTimer(&t.r) } diff --git a/src/pkg/time/tick.go b/src/pkg/time/tick.go index 8e43559048..b92c339c02 100644 --- a/src/pkg/time/tick.go +++ b/src/pkg/time/tick.go @@ -39,6 +39,8 @@ func NewTicker(d Duration) *Ticker { } // Stop turns off a ticker. After Stop, no more ticks will be sent. +// Stop does not close the channel, to prevent a read from the channel succeeding +// incorrectly. func (t *Ticker) Stop() { stopTimer(&t.r) } -- 2.48.1