Skip to content

Commit 5060f56

Browse files
committed
Merge branch 'phu/batcher-close-ctx'
2 parents d076e15 + 3e2bdcd commit 5060f56

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

batcher.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,16 @@ func (b *ChanBatcher[T, R]) worker() {
186186
go b.batchFnWithRecover(tasks)
187187
tasks = tasks[:0:0]
188188
case task, ok := <-b.taskCh:
189-
ctx := task.Ctx()
190189
if !ok {
191-
klog.Debugf(ctx, "ChanBatcher.worker|closed|%d tasks", len(tasks))
190+
ctx := context.Background()
192191
if len(tasks) > 0 {
192+
ctx = tasks[0].Ctx()
193193
go b.batchFnWithRecover(tasks)
194194
}
195+
klog.Debugf(ctx, "ChanBatcher.worker|closed|%d tasks", len(tasks))
195196
return
196197
}
198+
ctx := task.Ctx()
197199
if !task.IsDone() {
198200
select {
199201
case <-ctx.Done():

0 commit comments

Comments
 (0)