diff --git a/internal/logic/strategy/boot.go b/internal/logic/strategy/boot.go index 5fbb075..da0e3b5 100644 --- a/internal/logic/strategy/boot.go +++ b/internal/logic/strategy/boot.go @@ -19,11 +19,20 @@ func BootAiStart(key string, ymd int) { panic(err) } - var wg sync.WaitGroup + // Create a buffered channel with a capacity of 20 to act as a semaphore + semaphore := make(chan struct{}, 20) + var wg sync.WaitGroup for _, row := range datas { wg.Add(1) - go BootAiTask(row.ID, row.Code, &wg) + // Acquire a slot in the semaphore + semaphore <- struct{}{} + go func(row models.StratModel) { + defer wg.Done() + // Release the slot in the semaphore when done + defer func() { <-semaphore }() + BootAiTask(row.ID, row.Code, &wg) + }(row) } wg.Wait()