Skip to content

Commit ef4615a

Browse files
committed
Fix workers when channel gets closed
1 parent 09a63fb commit ef4615a

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

pool.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@ func (p *pool) Start(maxWorkers int, fn interface{}) error {
4646
go func() {
4747
for {
4848
select {
49-
case args := <-p.queue:
50-
h.Call(args)
49+
case args, ok := <-p.queue:
50+
if ok {
51+
h.Call(args)
52+
}
5153
case <-p.ctx.Done():
5254
return
5355
}

pool_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func delegateWorkToWorkers(t *testing.T, poolSize int, jobsAmount int, workersAm
6767
}
6868

6969
if sum == 0 {
70-
fmt.Errorf("Delegating job %d to %d workers faild", jobsAmount, workersAmount)
70+
fmt.Errorf("Delegating job %d to %d workers failed", jobsAmount, workersAmount)
7171
t.Fail()
7272
}
7373
}

0 commit comments

Comments
 (0)