Goroutine creation can be simplified using WaitGroup.Go (modernize)

This commit is contained in:
Holger Obermaier
2026-02-13 15:52:36 +01:00
parent 3eaea4ca62
commit 5829f86f4a
3 changed files with 6 additions and 12 deletions

View File

@@ -123,9 +123,7 @@ func (cm *collectorManager) Start() {
tick := make(chan time.Time)
cm.ticker.AddChannel(tick)
cm.wg.Add(1)
go func() {
defer cm.wg.Done()
cm.wg.Go(func() {
// Collector manager is done
done := func() {
// close all metric collectors
@@ -180,7 +178,7 @@ func (cm *collectorManager) Start() {
}
}
}
}()
})
// Collector manager is started
cclog.ComponentDebug("CollectorManager", "STARTED")

View File

@@ -102,9 +102,7 @@ func (c *metricCache) Start() {
return oldPeriod
}
c.wg.Add(1)
go func() {
defer c.wg.Done()
c.wg.Go(func() {
for {
select {
case <-c.done:
@@ -124,7 +122,7 @@ func (c *metricCache) Start() {
}
}
}
}()
})
cclog.ComponentDebug("MetricCache", "START")
}

View File

@@ -291,9 +291,7 @@ func (r *metricRouter) Start() {
r.cache.Start()
}
r.wg.Add(1)
go func() {
defer r.wg.Done()
r.wg.Go(func() {
for {
select {
@@ -324,7 +322,7 @@ func (r *metricRouter) Start() {
}
}
}
}()
})
cclog.ComponentDebug("MetricRouter", "STARTED")
}