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

Commit

Permalink
Merge pull request #22 from catmullet/fix_frozen_parent_workers
Browse files Browse the repository at this point in the history
fix frozen parent workers on cancel
  • Loading branch information
catmullet authored Feb 25, 2021
2 parents 6b77fb9 + 8dd5dbb commit 18517aa
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 18517aa

Please sign in to comment.