From bb0c294723e5be8fdba56a9e6f7e9f969c046644 Mon Sep 17 00:00:00 2001 From: jiangmencity Date: Tue, 10 Feb 2026 15:01:36 +0800 Subject: [PATCH] refactor: use WaitGroup.Go to simplify code Signed-off-by: jiangmencity --- block/internal/executing/executor.go | 6 +----- block/internal/reaping/reaper.go | 6 +----- block/internal/syncing/raft_retriever.go | 6 ++---- pkg/da/selector_test.go | 6 ++---- 4 files changed, 6 insertions(+), 18 deletions(-) diff --git a/block/internal/executing/executor.go b/block/internal/executing/executor.go index bf1b44b6cb..94417b9b79 100644 --- a/block/internal/executing/executor.go +++ b/block/internal/executing/executor.go @@ -154,11 +154,7 @@ func (e *Executor) Start(ctx context.Context) error { } // Start execution loop - e.wg.Add(1) - go func() { - defer e.wg.Done() - e.executionLoop() - }() + e.wg.Go(e.executionLoop) e.logger.Info().Msg("executor started") return nil diff --git a/block/internal/reaping/reaper.go b/block/internal/reaping/reaper.go index 203c66869d..67b2020216 100644 --- a/block/internal/reaping/reaper.go +++ b/block/internal/reaping/reaper.go @@ -78,11 +78,7 @@ func (r *Reaper) Start(ctx context.Context) error { r.ctx, r.cancel = context.WithCancel(ctx) // Start reaper loop - r.wg.Add(1) - go func() { - defer r.wg.Done() - r.reaperLoop() - }() + r.wg.Go(r.reaperLoop) r.logger.Info().Dur("interval", r.interval).Msg("reaper started") return nil diff --git a/block/internal/syncing/raft_retriever.go b/block/internal/syncing/raft_retriever.go index 4c5df22d9e..a20a9a0d6c 100644 --- a/block/internal/syncing/raft_retriever.go +++ b/block/internal/syncing/raft_retriever.go @@ -71,11 +71,9 @@ func (r *raftRetriever) Start(ctx context.Context) error { applyCh := make(chan raft.RaftApplyMsg, 100) r.raftNode.SetApplyCallback(applyCh) - r.wg.Add(1) - go func() { - defer r.wg.Done() + r.wg.Go(func() { r.raftApplyLoop(ctx, applyCh) - }() + }) return nil } diff --git a/pkg/da/selector_test.go b/pkg/da/selector_test.go index c25a35e682..6eda8c1dd6 100644 --- a/pkg/da/selector_test.go +++ b/pkg/da/selector_test.go @@ -137,14 +137,12 @@ func TestNoOpSelector_Concurrent(t *testing.T) { var wg sync.WaitGroup for i := 0; i < numGoroutines; i++ { - wg.Add(1) - go func() { - defer wg.Done() + wg.Go(func() { for j := 0; j < 100; j++ { addr := selector.Next() assert.Empty(t, addr) } - }() + }) } wg.Wait()