Skip to content

Commit

Permalink
fix(workerpool.go): move taskQueueChan initialization in Run method, …
Browse files Browse the repository at this point in the history
…if AddTask is called before Run, will cause a panic.
  • Loading branch information
luogz17 committed Dec 8, 2023
1 parent 99454e5 commit 4809c8f
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions common/utils/workerpool/workerpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@ type WorkerPool struct {
func NewWorkerPool(maxWorker int) *WorkerPool {
return &WorkerPool{
maxWorker: maxWorker,
taskQueueChan: nil,
taskQueueChan: make(chan func()),
wg: sync.WaitGroup{},
}
}

// Run runs WorkerPool
func (vwp *WorkerPool) Run() {
vwp.taskQueueChan = make(chan func())
for i := 0; i < vwp.maxWorker; i++ {
go func() {
for task := range vwp.taskQueueChan {
Expand Down

0 comments on commit 4809c8f

Please sign in to comment.