Skip to content

Commit

Permalink
refactor: get resolve err before resolving in loop
Browse files Browse the repository at this point in the history
  • Loading branch information
NgoKimPhu committed Dec 29, 2023
1 parent b4a777d commit 7f85b5c
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions batcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,17 @@ func (b *ChanBatcher[T, R]) batchFnWithRecover(tasks []T) {
}
logger.Errorf("ChanBatcher.goBatchFn|recovered from panic: %v\n%s", p, string(debug.Stack()))
var ret R
err, ok := p.(error)
if ok {
err = errors.Wrap(err, "batchFn panicked")
} else {
err = errors.Errorf("batchFn panicked: %v", p)
}
for _, task := range tasks {
if task.IsDone() {
continue
}
if err, ok := p.(error); ok {
task.Resolve(ret, errors.Wrap(err, "batchFn panicked"))
} else {
task.Resolve(ret, errors.Errorf("batchFn panicked: %v", p))
}
task.Resolve(ret, err)
}
}()
b.batchFn(tasks)
Expand Down

0 comments on commit 7f85b5c

Please sign in to comment.