mirror of
https://github.com/golang/go
synced 2024-11-20 08:44:39 -07:00
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
This commit is contained in:
parent
353fd1014c
commit
f383062e01
@ -5,6 +5,7 @@
|
|||||||
package time
|
package time
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -163,10 +164,11 @@ var onceStartTickerLoop sync.Once
|
|||||||
|
|
||||||
// NewTicker returns a new Ticker containing a channel that will
|
// NewTicker returns a new Ticker containing a channel that will
|
||||||
// send the time, in nanoseconds, every ns nanoseconds. It adjusts the
|
// 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 {
|
func NewTicker(ns int64) *Ticker {
|
||||||
if ns <= 0 {
|
if ns <= 0 {
|
||||||
return nil
|
panic(os.ErrorString("non-positive interval for NewTicker"))
|
||||||
}
|
}
|
||||||
c := make(chan int64, 1) // See comment on send in tickerLoop
|
c := make(chan int64, 1) // See comment on send in tickerLoop
|
||||||
t := &Ticker{
|
t := &Ticker{
|
||||||
|
Loading…
Reference in New Issue
Block a user