From a714b301ff415e38fb78b1dd3824ad905224d9b1 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Sun, 3 Apr 2022 12:22:13 +0800 Subject: [PATCH 1/2] fix(worker): don't start request task check worker count is zero or not before fetch the task. fix https://github.com/golang-queue/queue/issues/59 Signed-off-by: Bo-Yi Wu --- queue.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/queue.go b/queue.go index a5fcdc7..6e96c8f 100644 --- a/queue.go +++ b/queue.go @@ -81,6 +81,9 @@ func NewQueue(opts ...Option) (*Queue, error) { // Start to enable all worker func (q *Queue) Start() { + if q.workerCount == 0 { + return + } q.routineGroup.Run(func() { q.start() }) From 2320d461ccd2a6dd08648530451701851bf64089 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Sun, 3 Apr 2022 12:28:41 +0800 Subject: [PATCH 2/2] fix: test Signed-off-by: Bo-Yi Wu --- pool_test.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pool_test.go b/pool_test.go index 911cb86..e4e2626 100644 --- a/pool_test.go +++ b/pool_test.go @@ -28,3 +28,11 @@ func TestNewPoolWithQueueTask(t *testing.T) { p.Release() assert.Equal(t, 0, p.BusyWorkers()) } + +func TestPoolNumber(t *testing.T) { + p := NewPool(0) + p.Start() + // shutdown all, and now running worker is 0 + p.Release() + assert.Equal(t, 0, p.BusyWorkers()) +}