Browse Source

use a time.Ticker instead of the time.Sleep

Attila Oláh 11 năm trước cách đây
mục cha
commit
f47ededb99
1 tập tin đã thay đổi với 1 bổ sung2 xóa
  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)
 	}
 }