Browse Source

Use time.Tick everywhere else we should, too

Richard Crowley 11 years ago
parent
commit
3331190d5f
5 changed files with 5 additions and 10 deletions
  1. 1 2
      debug.go
  2. 1 2
      log.go
  3. 1 2
      runtime.go
  4. 1 2
      syslog.go
  5. 1 2
      writer.go

+ 1 - 2
debug.go

@@ -22,9 +22,8 @@ var (
 // Capture new values for the Go garbage collector statistics exported in
 // Capture new values for the Go garbage collector statistics exported in
 // debug.GCStats.  This is designed to be called as a goroutine.
 // debug.GCStats.  This is designed to be called as a goroutine.
 func CaptureDebugGCStats(r Registry, d time.Duration) {
 func CaptureDebugGCStats(r Registry, d time.Duration) {
-	for {
+	for _ = range time.Tick(d) {
 		CaptureDebugGCStatsOnce(r)
 		CaptureDebugGCStatsOnce(r)
-		time.Sleep(d)
 	}
 	}
 }
 }
 
 

+ 1 - 2
log.go

@@ -8,7 +8,7 @@ import (
 // Output each metric in the given registry periodically using the given
 // Output each metric in the given registry periodically using the given
 // logger.
 // logger.
 func Log(r Registry, d time.Duration, l *log.Logger) {
 func Log(r Registry, d time.Duration, l *log.Logger) {
-	for {
+	for _ = range time.Tick(d) {
 		r.Each(func(name string, i interface{}) {
 		r.Each(func(name string, i interface{}) {
 			switch metric := i.(type) {
 			switch metric := i.(type) {
 			case Counter:
 			case Counter:
@@ -66,6 +66,5 @@ func Log(r Registry, d time.Duration, l *log.Logger) {
 				l.Printf("  mean rate:   %12.2f\n", t.RateMean())
 				l.Printf("  mean rate:   %12.2f\n", t.RateMean())
 			}
 			}
 		})
 		})
-		time.Sleep(d)
 	}
 	}
 }
 }

+ 1 - 2
runtime.go

@@ -49,9 +49,8 @@ var (
 // Capture new values for the Go runtime statistics exported in
 // Capture new values for the Go runtime statistics exported in
 // runtime.MemStats.  This is designed to be called as a goroutine.
 // runtime.MemStats.  This is designed to be called as a goroutine.
 func CaptureRuntimeMemStats(r Registry, d time.Duration) {
 func CaptureRuntimeMemStats(r Registry, d time.Duration) {
-	for {
+	for _ = range time.Tick(d) {
 		CaptureRuntimeMemStatsOnce(r)
 		CaptureRuntimeMemStatsOnce(r)
-		time.Sleep(d)
 	}
 	}
 }
 }
 
 

+ 1 - 2
syslog.go

@@ -11,7 +11,7 @@ import (
 // Output each metric in the given registry to syslog periodically using
 // Output each metric in the given registry to syslog periodically using
 // the given syslogger.
 // the given syslogger.
 func Syslog(r Registry, d time.Duration, w *syslog.Writer) {
 func Syslog(r Registry, d time.Duration, w *syslog.Writer) {
-	for {
+	for _ = range time.Tick(d) {
 		r.Each(func(name string, i interface{}) {
 		r.Each(func(name string, i interface{}) {
 			switch metric := i.(type) {
 			switch metric := i.(type) {
 			case Counter:
 			case Counter:
@@ -74,6 +74,5 @@ func Syslog(r Registry, d time.Duration, w *syslog.Writer) {
 				))
 				))
 			}
 			}
 		})
 		})
-		time.Sleep(d)
 	}
 	}
 }
 }

+ 1 - 2
writer.go

@@ -10,9 +10,8 @@ import (
 // Write sorts writes each metric in the given registry periodically to the
 // Write sorts writes each metric in the given registry periodically to the
 // given io.Writer.
 // given io.Writer.
 func Write(r Registry, d time.Duration, w io.Writer) {
 func Write(r Registry, d time.Duration, w io.Writer) {
-	for {
+	for _ = range time.Tick(d) {
 		WriteOnce(r, w)
 		WriteOnce(r, w)
-		time.Sleep(d)
 	}
 	}
 }
 }