Explorar o código

use a time.Ticker instead of the time.Sleep

Attila Oláh %!s(int64=11) %!d(string=hai) anos
pai
achega
f47ededb99
Modificáronse 1 ficheiros con 1 adicións e 2 borrados
  1. 1 2
      json.go

+ 1 - 2
json.go

@@ -71,9 +71,8 @@ func (r StandardRegistry) MarshalJSON() ([]byte, error) {
 // WriteJSON writes metrics from the given registry  periodically to the
 // specified io.Writer as JSON.
 func WriteJSON(r Registry, d time.Duration, w io.Writer) {
-	for {
+	for _ = range time.Tick(d) {
 		WriteJSONOnce(r, w)
-		time.Sleep(d)
 	}
 }