c := time.Tick(1 * time.Second) last := time.Now() ticker <-‐ last // sends tick once at first ! for t := range c { if t.Second() == 0 || t.After(last.Add(1*time.Minute)) { last = t ticker <-‐ t } } }()
Start collectMetrics concurrently // so that it does not prevent runnnig next collectMetrics. sem := make(chan uint, COLLECT_METRICS_WORKER_MAX) for tickedTime := range ticker { sem <-‐ 1 go func() { metricsResult <-‐ agent.collectMetrics(tickedTime) <-‐sem }() } }()
:= metrics.Values(make(map[string]float64)) for { select { case values := <-‐processed: allValues.Merge(values) case <-‐finish: result <-‐ allValues return } } }()