refactor: use WaitGroup.Go to simplify code (#16539)

### Summary

Adopt sync.WaitGroup.Go (Go 1.25) to simplify tracked goroutine
spawning. This replaces the error-prone trio of wg.Add(1), go func(),
and defer wg.Done() with a single, self-contained call.

More info: https://github.com/golang/go/issues/63796

Signed-off-by: grandpig <grandpig@outlook.com>
This commit is contained in:
grandpig
2026-07-02 13:41:53 +08:00
committed by GitHub
parent d0d0339428
commit 17e3e34e78
22 changed files with 69 additions and 138 deletions

View File

@@ -212,9 +212,7 @@ func NewVariableWatcher(store VariableStore) *VariableWatcher {
// Start starts watching for variable changes
func (w *VariableWatcher) Start(interval time.Duration) {
w.wg.Add(1)
go func() {
defer w.wg.Done()
w.wg.Go(func() {
ticker := time.NewTicker(interval)
defer ticker.Stop()
@@ -228,7 +226,7 @@ func (w *VariableWatcher) Start(interval time.Duration) {
return
}
}
}()
})
common.Info("Variable watcher started", zap.Duration("interval", interval))
}