summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Pike <r@golang.org>2011-01-07 14:41:46 -0800
committerRob Pike <r@golang.org>2011-01-07 14:41:46 -0800
commit565234aaf583da758c34cd97b23d4f6cec3332fa (patch)
tree94b513a08e92b2a4315dd5f98f7aeeb7a8818223
parent87d353264ddbaae9f6d055adc2c1879824207f6a (diff)
downloadgo-565234aaf583da758c34cd97b23d4f6cec3332fa.tar.gz
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 issue 1392. R=rsc, adg CC=golang-dev http://codereview.appspot.com/3896042
-rw-r--r--src/pkg/time/tick.go6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/pkg/time/tick.go b/src/pkg/time/tick.go
index 047468b81..8f7d4226f 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{