]> Cypherpunks repositories - gostls13.git/commitdiff
time.NewTicker: panic for intervals <= 0.
authorRob Pike <r@golang.org>
Fri, 7 Jan 2011 22:41:46 +0000 (14:41 -0800)
committerRob Pike <r@golang.org>
Fri, 7 Jan 2011 22:41:46 +0000 (14:41 -0800)
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

src/pkg/time/tick.go

index 047468b81fbab58e1a73efe73ee63520bf81e319..8f7d4226fedcb3d75675fdd87f5396b2a442b16f 100644 (file)
@@ -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{