Skip to content

Commit

Permalink
fix(workerpool.go): add nil check in AddTask method to prevent adding…
Browse files Browse the repository at this point in the history
… nil task to reduce the worker number.
  • Loading branch information
luogz17 committed Dec 8, 2023
1 parent 4809c8f commit 72cdf4e
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions common/utils/workerpool/workerpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,8 @@ func (vwp *WorkerPool) Run() {
for i := 0; i < vwp.maxWorker; i++ {
go func() {
for task := range vwp.taskQueueChan {
if task != nil {
task()
vwp.wg.Done()
} else {
return
}
task()
vwp.wg.Done()
}
}()
}
Expand All @@ -45,6 +41,9 @@ func (vwp *WorkerPool) Stop() {

// AddTask adds a task to WorkerPool
func (vwp *WorkerPool) AddTask(task func()) {
if task == nil {
return
}
vwp.wg.Add(1)
vwp.taskQueueChan <- task
}

0 comments on commit 72cdf4e

Please sign in to comment.