Skip to content
This repository has been archived by the owner on Feb 20, 2024. It is now read-only.

Commit

Permalink
fix issue with child workers stop and parent workers frozen on channe…
Browse files Browse the repository at this point in the history
…l send.
  • Loading branch information
catmullet committed Feb 25, 2021
1 parent 6b77fb9 commit 8dd5dbb
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions workers.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,13 @@ func NewWorker(ctx context.Context, workerFunction WorkerObject, numberOfWorkers

// Send wrapper to send interface through workers "in" channel
func (iw *Worker) Send(in interface{}) {
select {
case <-iw.IsDone():
return
default:
iw.inChan <- in
for {
select {
case <-iw.IsDone():
return
case iw.inChan <- in:
return
}
}
}

Expand Down Expand Up @@ -119,11 +121,13 @@ func (iw *Worker) workFunc() error {

// Out pushes value to workers out channel
func (iw *Worker) Out(out interface{}) {
select {
case <-iw.Ctx.Done():
return
default:
iw.outChan <- out
for {
select {
case <-iw.Ctx.Done():
return
case iw.outChan <- out:
return
}
}
}

Expand Down

0 comments on commit 8dd5dbb

Please sign in to comment.