Skip to content

Commit

Permalink
Fix race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
Corentin Clabaut committed Jun 11, 2024
1 parent f59ff90 commit bdb616c
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions pond.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,11 +353,6 @@ func (p *WorkerPool) stop(waitForQueuedTasksToComplete bool) {
// Mark pool as stopped
atomic.StoreInt32(&p.stopped, 1)

// close tasks channel (only once, in case multiple concurrent calls to StopAndWait are made)
p.tasksCloseOnce.Do(func() {
close(p.tasks)
})

if waitForQueuedTasksToComplete {
// Wait for all queued tasks to complete
p.tasksWaitGroup.Wait()
Expand All @@ -369,6 +364,11 @@ func (p *WorkerPool) stop(waitForQueuedTasksToComplete bool) {
// Terminate all workers & purger goroutine
p.contextCancel()

// close tasks channel (only once, in case multiple concurrent calls to StopAndWait are made)
p.tasksCloseOnce.Do(func() {
close(p.tasks)
})

// Wait for all workers & purger goroutine to exit
p.workersWaitGroup.Wait()
}
Expand Down

0 comments on commit bdb616c

Please sign in to comment.