Skip to content

Commit

Permalink
add comment to explain why it's not necessary to hold a lock on results
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Hahling <[email protected]>
  • Loading branch information
rolinh committed Feb 3, 2021
1 parent 986656c commit 32bff70
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions workerpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ func (wp *WorkerPool) Drain() ([]Task, error) {

wp.wg.Wait()

// It's not necessary to hold a lock when reading wp.results as no other
// routine is running at this point besides the "run" routine which should
// be waiting on the tasks channel.
res := make([]Task, len(wp.results))
for i, t := range wp.results {
res[i] = t
Expand Down

0 comments on commit 32bff70

Please sign in to comment.