diff options
author | Rob Pike <r@golang.org> | 2011-01-07 14:41:46 -0800 |
---|---|---|
committer | Rob Pike <r@golang.org> | 2011-01-07 14:41:46 -0800 |
commit | f383062e014d44872e8bd450a538fc45b7bee5c8 (patch) | |
tree | c5d7e33de4c2653cf89fef43ae95d1308ceaa065 | |
parent | 353fd1014c78b3b76fb5233f477677e0333e5f1a (diff) | |
download | go-f383062e014d44872e8bd450a538fc45b7bee5c8.tar.gz go-f383062e014d44872e8bd450a538fc45b7bee5c8.zip |
time.NewTicker: panic for intervals <= 0.
Not absolutely certain it's right to do this, but since there's
no error value coming back, it seems reasonable.
Fixes #1392.
R=rsc, adg
CC=golang-dev
https://golang.org/cl/3896042
-rw-r--r-- | src/pkg/time/tick.go | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/pkg/time/tick.go b/src/pkg/time/tick.go index 047468b81f..8f7d4226fe 100644 --- a/src/pkg/time/tick.go +++ b/src/pkg/time/tick.go @@ -5,6 +5,7 @@ package time import ( + "os" "sync" ) @@ -163,10 +164,11 @@ var onceStartTickerLoop sync.Once // NewTicker returns a new Ticker containing a channel that will // send the time, in nanoseconds, every ns nanoseconds. It adjusts the -// intervals to make up for pauses in delivery of the ticks. +// intervals to make up for pauses in delivery of the ticks. The value of +// ns must be greater than zero; if not, NewTicker will panic. func NewTicker(ns int64) *Ticker { if ns <= 0 { - return nil + panic(os.ErrorString("non-positive interval for NewTicker")) } c := make(chan int64, 1) // See comment on send in tickerLoop t := &Ticker{ |