Skip to content

Commit a83a0bf

Browse files
authored
Merge pull request #69 from mcarmonaa/fix/lock-on-wait
*: do not lock on worker pool wait and wait backoff on error for scheduling
2 parents 3897bd6 + 9f14823 commit a83a0bf

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

scheduler.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,18 +91,19 @@ func (s *jobScheduler) Schedule() {
9191
continue
9292
}
9393

94-
select {
95-
case <-s.cancel:
96-
return
97-
case <-time.After(s.backoff.Duration()):
98-
}
9994
}
10095

10196
if ErrJobSource.Is(err) {
10297
close(s.jobs)
10398
return
10499
}
105100

101+
select {
102+
case <-s.cancel:
103+
return
104+
case <-time.After(s.backoff.Duration()):
105+
}
106+
106107
continue
107108
}
108109

worker_pool.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,8 @@ func (wp *WorkerPool) remove(n int) {
106106
wg.Wait()
107107
}
108108

109-
// Wait waits for the workers to finish. A worker will finish when the queue to
110-
// retrieve jobs from is closed.
109+
// Wait waits for the workers to finish.
111110
func (wp *WorkerPool) Wait() {
112-
<-wp.resize
113-
defer func() { wp.resize <- struct{}{} }()
114-
115111
wp.wg.Wait()
116112
wp.workers = nil
117113
wp.opts.Metrics.Stop(false)

0 commit comments

Comments
 (0)