Skip to content

Commit

Permalink
Merge branch 'phu/batcher-close-ctx'
Browse files Browse the repository at this point in the history
  • Loading branch information
NgoKimPhu committed Jan 8, 2024
2 parents d076e15 + 3e2bdcd commit 5060f56
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions batcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,16 @@ func (b *ChanBatcher[T, R]) worker() {
go b.batchFnWithRecover(tasks)
tasks = tasks[:0:0]
case task, ok := <-b.taskCh:
ctx := task.Ctx()
if !ok {
klog.Debugf(ctx, "ChanBatcher.worker|closed|%d tasks", len(tasks))
ctx := context.Background()
if len(tasks) > 0 {
ctx = tasks[0].Ctx()
go b.batchFnWithRecover(tasks)
}
klog.Debugf(ctx, "ChanBatcher.worker|closed|%d tasks", len(tasks))
return
}
ctx := task.Ctx()
if !task.IsDone() {
select {
case <-ctx.Done():
Expand Down

0 comments on commit 5060f56

Please sign in to comment.