Skip to content

Commit

Permalink
wait the for "run" routine to return on Close
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 32bff70 commit b873420
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions workerpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func (wp *WorkerPool) run() {
<-wp.workers
}()
}
close(wp.workers)
}

// Submit submits f for processing by a worker. The given id is useful for
Expand Down Expand Up @@ -153,5 +154,8 @@ func (wp *WorkerPool) Close() error {
// At this point, all routines have returned. This means that Submit is not
// pending to write to the task channel and it is thus safe to close it.
close(wp.tasks)

// wait for the "run" routine
<-wp.workers
return nil
}

0 comments on commit b873420

Please sign in to comment.