Skip to content

Commit

Permalink
fix: use background ctx on close as task from closed chan is nil
Browse files Browse the repository at this point in the history
  • Loading branch information
NgoKimPhu committed Jan 8, 2024
1 parent d076e15 commit 3e2bdcd
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 3e2bdcd

Please sign in to comment.