From ee90cf2e367f189bc2ab338a86702e390edaacc3 Mon Sep 17 00:00:00 2001 From: Yun Date: Wed, 27 May 2026 14:53:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=99=90=E5=88=B6=E5=B9=B6?= =?UTF-8?q?=E5=8F=91=E7=9A=84=E7=94=9F=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cluster.go | 5 ++++- once.go | 7 +++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/cluster.go b/cluster.go index 5f933c1..e93d46e 100644 --- a/cluster.go +++ b/cluster.go @@ -550,7 +550,7 @@ func (c *Cluster) executeTasks() { return case <-c.ctx.Done(): return - case c.workerChan <- struct{}{}: + default: func() { if c.usePriority && !c.priority.IsLatest(c.ctx) { @@ -572,6 +572,9 @@ func (c *Cluster) executeTasks() { return } + // 限制并发数量 + c.workerChan <- struct{}{} + go c.processTask(taskID[1]) }() } diff --git a/once.go b/once.go index fd7cd7a..571af20 100644 --- a/once.go +++ b/once.go @@ -309,7 +309,7 @@ func (l *Once) executeTasks() { return case <-l.ctx.Done(): return - case l.workerChan <- struct{}{}: + default: func() { if l.usePriority && !l.priority.IsLatest(l.ctx) { @@ -330,7 +330,10 @@ func (l *Once) executeTasks() { l.logger.Errorf(l.ctx, "Invalid task data: %v", keys) return } - // 处理任务 + + // 限制并发数量 + l.workerChan <- struct{}{} + go l.processTask(keys[1]) }() }